This repository contains the code for the ECS Multi-region workshop.
The app
folder contains a Python Flask application for books API that uses DynamoDB as the data store.
The cdk
folder contains the infrastructure code that deploys this application to Amazon Elastic Container Service (Amazon ECS).
The repository contains two main branches that can be used:
- feature/single_region: Used to deploy the application to a single AWS region.
- main: Used to deploy the application to two AWS regions.
In this section we will explain how to deploy the application to 2 different regions.
- Navigate to the CDK folder:
cd cdk
- Install NPM packages:
npm install
- Make sure that the AWS CLI uses the main region:
aws configure set region <your main region of choice (e.g. us-east-1)>
- Bootstrap the AWS main region:
cdk bootstrap
- Export environment variables needed for bootstrapping the secondary region:
export WORKSHOP_ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text)
export WORKSHOP_SECONDARY_REGION=<your secondary region of choice (e.g. us-west-1)>
- Bootstrap the AWS secondary region:
cdk bootstrap aws://$WORKSHOP_ACCOUNT_ID/$WORKSHOP_SECONDARY_REGION
- Deploy the foundation stack to the main region:
cdk deploy workshop-foundation-main
- Deploy the foundation stack to the secondary region:
cdk deploy workshop-foundation-secondary
To deploy the data stack to both regions, run:
cdk deploy workshop-data
The following steps require Docker to be installed and running.
- Deploy the backend stack to the main region:
cdk deploy workshop-backend-main --require-approval never
- Deploy the backend stack to the secondary region:
cdk deploy workshop-backend-secondary --require-approval never
Before we can deploy the routing stack, we will need to export the secondary region's load balancer ARN as an environment variable. The environment variable will be referenced by the CDK code.
export WORKSHOP_SECONDARY_ALB_ARN=$(aws elbv2 describe-load-balancers --names "workshop-alb" --query "LoadBalancers[0].LoadBalancerArn" --output text --region $WORKSHOP_SECONDARY_REGION)
Then we can deploy the routing stack as follows:
cdk deploy workshop-routing --require-approval never
- Navigate to Global Accelerators console
- From left navigation select "Accelerators", and click on workshop-accelerator.
- Copy the DNS name, then paste it in a new browser tab. Append
/healthcheck
to the URL. You should be able to see a JSON response for the health check.