tree-schema-ecs-example

This repo contains the code, templates and other development resources that along with the Tree Schema articles for creating a complete ECS deployment

Note - to run these commands you will need to have the AWS SAM CLI installed.

Article 1 - VPC deployment

In the first article the following VPC is deployed, which generally contains the following resources:

VPC Resources

The VPC can be deployed by running this command from the root directory (change my-vpc to the name of the stack you would like):

sam deploy \
--template templates/vpc-template.yaml \
--stack-name my-vpc \
--capabilities CAPABILITY_AUTO_EXPAND

Article 2 - ECS Cluster, CloudFront Distribution & S3 Buckets

In the second article the following CloudFormation, ECS resources are deployed in line with the following deployment:

ECS Deployment Resources

The ECS resources, including the ECS cluster, required roles, CloudFront distribution, and S3 buckets can be deployed by running this command from the root directory (change my-cluster-resources to the name of the stack you would like and your-user-id to your user's user ID):

sam deploy \
--template templates/ecs-cluster-template.yaml \
--stack-name my-cluster-resources \
--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM \
--parameter-overrides "ParameterKey=YourUserId,ParameterValue=your-user-id"

Article 3 - Creating the Django & Celery Application

In the third article the Django & Celery app are created.

The application can be found under the app directory and generally has the following general flow:

ECS Deployment Resources

This repo can be cloned and the app can be run locally. Redis must be running locally on port 6379. Execute the following command in the app directory to start Django:

python manage.py runserver 0.0.0.0:8000

And in a second terminal, but the same directory, run the following to start Celery:

celery -A ecs_example worker -l info 

Article 4 - Deploying the App to ECS

In the fourth article the app is deployed to ECS.

Assuming that you have been following along with the other walkthroughs, you will only need to update a few parameters in the mapping section of the template. The template can be found here:

./templates/django-app.yaml

The containers can be built with the following command from this directory:

sh build.sh

And can be deployed with

sam deploy -t templates/django-app.yaml \
--stack-name django-ecs-app \
--capabilities CAPABILITY_IAM  

Article 5 - Getting Ready for Prod

In the fifth and final article the finishing touches are put in place to use the app in production. Emails are sent with SES, autoscaling is put in place and Route53 sends traffic from our domain to the app.

With the new updates, the containers will need to be rebuilt with the following command from this directory:

sh build.sh

And the services will need to be updated / redeployed with the same command.

sam deploy -t templates/django-app.yaml \
--stack-name django-ecs-app \
--capabilities CAPABILITY_IAM