Skip to content

aws-samples/amazon-ecs-multi-region

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ECS Multi-Region Workshop

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).

Prerequisites

  1. AWS CDK
  2. AWS CLI
  3. Docker

Branches

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.

Deploying to AWS

In this section we will explain how to deploy the application to 2 different regions.

Bootstrapping CDK

  1. Navigate to the CDK folder:
cd cdk
  1. Install NPM packages:
npm install
  1. Make sure that the AWS CLI uses the main region:
aws configure set region <your main region of choice (e.g. us-east-1)>
  1. Bootstrap the AWS main region:
cdk bootstrap
  1. 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)>
  1. Bootstrap the AWS secondary region:
cdk bootstrap aws://$WORKSHOP_ACCOUNT_ID/$WORKSHOP_SECONDARY_REGION

Deploying the foundation stack

  1. Deploy the foundation stack to the main region:
cdk deploy workshop-foundation-main
  1. Deploy the foundation stack to the secondary region:
cdk deploy workshop-foundation-secondary

Deploying the data stack

To deploy the data stack to both regions, run:

cdk deploy workshop-data

Deploying the backend stack

The following steps require Docker to be installed and running.

  1. Deploy the backend stack to the main region:
cdk deploy workshop-backend-main --require-approval never
  1. Deploy the backend stack to the secondary region:
cdk deploy workshop-backend-secondary --require-approval never

Deploying the routing stack

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

Test out the API

  • 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.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •