Skip to content

awsshivs/cloudformation-multiregional-deployments

 
 

Repository files navigation

Gaining more control over Multi-Regional AWS CloudFormation deployments.

AWS Immersion Days use a tool called Event Engine, which only supports deploying templates into a single region. This project works around that limitation by creating a deployment Stepfunction and then executing CloudFormation cross region. There is also support for dependencies (e.g., configure a primary region before secondary).

How is the project organized

  • Infrastructure as Code. The app.py declares all resources for deploying the Deployer service.
  • Supporting Lambda. The src folder declares the Lambda functions that support the Deployment State Machine.

How do I start my build window

User must first install AWS CDK in Python. Your specific workstation might require specifying python3** and pip3 explicitly. Running python --version should confirm the local version is 3.x -- not 2.x!

apt-get -y update && apt-get -y install --no-install-recommends npm
npm install -g aws-cdk
python3 -m pip install --upgrade pip
pip3 install -r ./requirements.txt

Next setup AWS programmatic access via the CLI.

pip3/ install awscli
aws configure

Optionally, developers with Docker can use the predefined image.

# Build the image
docker build -t cdk-deployer .

# Launch an interactive terminal
MOUNT_AWS_CREDS=-v ~/.aws:/root/.aws
MOUNT_GIT_SRC=-v `pwd`:/files 
docker run -it $MOUNT_AWS_CREDS $MOUNT_GIT_SRC -w /files --entrypoint bash cdk-deployer

How do I deploy these resources

  1. Create an Amazon S3 bucket in the Deployer's region
export REGION=us-west-1
S3_ASSET_BUCKET=yournamehere-$REGION
aws s3 --region $REGION mb s3://$S3_ASSET_BUCKET
  1. Export the deployment environment variables
export S3_ASSET_BUCKET=yournamehere-$REGION

# No trailing slash!!
export S3_ASSET_PREFIX=deployment/example
  1. Run the deployment script
./deploy.sh
  1. Create a stack set with the EventEngine.template.json output.
aws cloudformation create-stack --stack-name DR-Deployer --region $REGION --template-url s3://$S3_ASSET_BUCKET/$S3_ASSET_PREFIX/EventEngine.template.json

Is second deployment faster

Optionally, yes. During deploy.sh it needs to convert the compress the Lambda functions into .zip files. Afterward, you can reuse that content via the below command.

# https://docs.aws.amazon.com/cdk/latest/guide/environments.html
export CDK_DEFAULT_REGION=us-west-1
cdk deploy -a ./app.py 

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 89.6%
  • Shell 8.9%
  • Dockerfile 1.5%