22# This assumes all of the OS-level configuration has been completed and git repo has already been cloned
33#
44# Usage: This script should be executed from the package root directory
5- # ./deployment/build-s3-dist.sh source-bucket-base-name template-bucket-base-name trademarked-solution-name version-code
5+ # ./deployment/build-s3-dist.sh source-bucket-base-name template-bucket-base-name trademarked-solution-name version-code enable-opt-in-region-support
66#
77# Parameters:
8- # - source-bucket-base-name: Name for the S3 bucket location where the template will source the Lambda
8+ # - source-bucket-base-name: Name for the S3 bucket location where the template will source the Lambda
99# code from. The template will append '-[region_name]' to this bucket name.
1010# For example: ./build-s3-dist.sh solutions template-bucket my-solution v1.0.0
1111# The template will then expect the source code to be located in the solutions-[region_name] bucket
1414#
1515# - trademarked-solution-name: name of the solution for consistency
1616#
17- # - version-code: version of the package
17+ # - version-code: version of the package
18+ #
19+ # - enable-opt-in-region-support: (Optional Boolean) Flag to enable opt-in region support. Pass `true` to set this argument.
20+
1821
1922# Hard exit on failure
2023set -e
2124
2225# Check to see if input has been provided:
23- if [ $# != 4 ]; then
24- echo " Please provide the base source bucket name, template-bucket, trademark approved solution name, and version "
25- echo " For example: ./deployment/build-s3-dist.sh solutions template-bucket trademarked-solution-name v1.0.0"
26+ if [ $# -lt 4 ]; then
27+ echo " Please provide the base source bucket name, template-bucket, trademark approved solution name, version and (Optional) enable-opt-in-region-support flag "
28+ echo " For example: ./deployment/build-s3-dist.sh solutions template-bucket trademarked-solution-name v1.0.0 true "
2629 exit 1
2730fi
2831
@@ -34,6 +37,17 @@ CODE_BUCKET_NAME=$1
3437TEMPLATE_BUCKET_NAME=$2
3538SOLUTION_NAME=$3
3639VERSION_NUMBER=$4
40+ ENABLE_OPT_IN_REGION_SUPPORT=$5
41+
42+ # Handle opt-in region builds in backwards compatible way,
43+ # Requires customer to set IS_OPT_IN_REGION parameter
44+ SCRIPT_BUCKET_NAME=$( echo " ${TEMPLATE_BUCKET_NAME} " )
45+ DISTRIBUTION_BUCKET_NAME=$( echo " ${TEMPLATE_BUCKET_NAME} " )
46+ if [[ " ${ENABLE_OPT_IN_REGION_SUPPORT} " = " true" ]]; then
47+ echo " Building with opt-in region support"
48+ SCRIPT_BUCKET_NAME+=' -${AWS_REGION}' # Regionalized Buildspec
49+ DISTRIBUTION_BUCKET_NAME+=' -${AWS::Region}' # Regionalized CFN Template
50+ fi
3751
3852 echo " ------------------------------------------------------------------------------"
3953 echo " [Init] Clean old dist and recreate directories"
@@ -68,8 +82,13 @@ replace="s/%DIST_BUCKET_NAME%/$CODE_BUCKET_NAME/g"
6882echo " sed -i -e $replace $template_dist_dir /custom-control-tower-initiation.template"
6983sed -i -e " $replace " " $template_dist_dir " /custom-control-tower-initiation.template
7084
71- echo -e " \n Updating template bucket in the template with $TEMPLATE_BUCKET_NAME "
72- replace=" s/%TEMPLATE_BUCKET_NAME%/$TEMPLATE_BUCKET_NAME /g"
85+ echo -e " \n Updating template bucket in the template with $DISTRIBUTION_BUCKET_NAME "
86+ replace=" s/%TEMPLATE_BUCKET_NAME%/$DISTRIBUTION_BUCKET_NAME /g"
87+ echo " sed -i -e $replace $template_dist_dir /custom-control-tower-initiation.template"
88+ sed -i -e " $replace " " $template_dist_dir " /custom-control-tower-initiation.template
89+
90+ echo -e " \n Updating template bucket in the template with $SCRIPT_BUCKET_NAME "
91+ replace=" s/%SCRIPT_BUCKET_NAME%/$SCRIPT_BUCKET_NAME /g"
7392echo " sed -i -e $replace $template_dist_dir /custom-control-tower-initiation.template"
7493sed -i -e " $replace " " $template_dist_dir " /custom-control-tower-initiation.template
7594
@@ -93,23 +112,30 @@ zip -Xr "$build_dist_dir"/custom-control-tower-configuration.zip ./*
93112echo -e " \n*** Build regional config zip file"
94113# Support all regions in https://docs.aws.amazon.com/controltower/latest/userguide/region-how.html + GovCloud regions
95114declare -a region_list=(
96- " us-east-1"
97- " us-east-2"
98- " us-west-2"
99- " ca-central-1"
100- " ap-southeast-2"
115+ " af-south-1"
116+ " ap-east-1"
117+ " ap-northeast-1"
118+ " ap-northeast-2"
119+ " ap-northeast-3"
120+ " ap-south-1"
101121 " ap-southeast-1"
122+ " ap-southeast-2"
123+ " ap-southeast-3"
124+ " ca-central-1"
102125 " eu-central-1"
126+ " eu-north-1"
127+ " eu-south-1"
103128 " eu-west-1"
104129 " eu-west-2"
105- " eu-north-1"
106- " ap-south-1"
107- " ap-northeast-2"
108- " ap-northeast-1"
109130 " eu-west-3"
131+ " me-south-1"
110132 " sa-east-1"
111- " us-gov-west-1"
133+ " us-east-1"
134+ " us-east-2"
112135 " us-gov-east-1"
136+ " us-gov-west-1"
137+ " us-west-1"
138+ " us-west-2"
113139)
114140for region in " ${region_list[@]} "
115141do
126152# Copy Lambda Zip Files to the Global S3 Assets
127153echo -e " \n Copying lambda zip files to Global S3 Assets"
128154cp " $build_dist_dir " /* .zip " $template_dist_dir " /
155+
0 commit comments