├── test ├── cycle.sh ├── endless.sh ├── up.sh └── down.sh ├── mu.yml ├── LICENSE ├── README.md └── images └── web-app-ecs-architecture.svg /test/cycle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./up.sh 4 | ./down.sh 5 | -------------------------------------------------------------------------------- /mu.yml: -------------------------------------------------------------------------------- 1 | --- 2 | environments: 3 | - name: acceptance 4 | provider: ecs-fargate 5 | - name: production 6 | provider: ecs-fargate 7 | 8 | -------------------------------------------------------------------------------- /test/endless.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | count=1 4 | 5 | while true; do 6 | echo "================================" 7 | echo "Beginning test ${count} build at $(date)" 8 | ./cycle.sh 9 | echo "Ending test ${count} build at $(date)" 10 | echo "================================" 11 | ((count++)) 12 | done 13 | -------------------------------------------------------------------------------- /test/up.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | echo "================================" 6 | echo "Beginning acceptance platform build at $(date)" 7 | cd ~/environment/ecsdemo-platform 8 | mu env up acceptance 9 | echo "================================" 10 | echo "Beginning production platform build at $(date)" 11 | mu env up production 12 | 13 | echo "================================" 14 | echo "Beginning frontend pipeline build at $(date)" 15 | cd ~/environment/ecsdemo-frontend 16 | mu pipeline up -t $GITHUB_TOKEN 17 | 18 | echo "================================" 19 | echo "Beginning nodejs pipeline build at $(date)" 20 | cd ~/environment/ecsdemo-nodejs 21 | mu pipeline up -t $GITHUB_TOKEN 22 | 23 | echo "================================" 24 | echo "Beginning crystal pipeline build at $(date)" 25 | cd ~/environment/ecsdemo-crystal 26 | mu pipeline up -t $GITHUB_TOKEN 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 AWS Devops 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/down.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | cd ~/environment/ecsdemo-crystal 6 | mu pipeline term 7 | 8 | cd ~/environment/ecsdemo-nodejs 9 | mu pipeline term 10 | 11 | echo "================================" 12 | echo "Beginning frontend pipeline term at $(date)" 13 | cd ~/environment/ecsdemo-frontend 14 | mu pipeline term 15 | 16 | echo "================================" 17 | echo "Beginning acceptance platform term at $(date)" 18 | cd ~/environment/ecsdemo-platform 19 | mu env term acceptance 20 | echo "================================" 21 | echo "Beginning production platform term at $(date)" 22 | mu env term production 23 | 24 | echo "================================" 25 | echo "Beginning ecr repo delete at $(date)" 26 | aws ecr delete-repository --repository-nam ${MU_NAMESPACE}-ecsdemo-frontend --force || true 27 | aws ecr delete-repository --repository-nam ${MU_NAMESPACE}-ecsdemo-nodejs --force || true 28 | aws ecr delete-repository --repository-nam ${MU_NAMESPACE}-ecsdemo-crystal --force ||true 29 | 30 | echo "================================" 31 | echo "Beginning s3 bucket delete at $(date)" 32 | export REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/\(.*\)[a-z]/\1/' 33 | ) 34 | export ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) 35 | aws s3 rm --recursive s3://${MU_NAMESPACE}-codedeploy-${REGION}-${ACCOUNT_ID} 36 | aws s3 rm --recursive s3://${MU_NAMESPACE}-codepipeline-${REGION}-${ACCOUNT_ID} 37 | 38 | echo "================================" 39 | echo "Beginning cf stack delete at $(date)" 40 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-iam-service-ecsdemo-frontend-acceptance 41 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-iam-service-ecsdemo-frontend-production 42 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-iam-service-ecsdemo-nodejs-acceptance 43 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-iam-service-ecsdemo-nodejs-production 44 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-iam-service-ecsdemo-crystal-acceptance 45 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-iam-service-ecsdemo-crystal-production 46 | 47 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-repo-ecsdemo-frontend 48 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-repo-ecsdemo-nodejs 49 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-repo-ecsdemo-crystal 50 | 51 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-bucket-codedeploy 52 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-bucket-codepipeline 53 | 54 | echo "================================" 55 | echo "Beginning sleep 300 at $(date)" 56 | sleep 300 # delay waiting for all the other CF stacks to be deleted -- replace with a count of stacks or something 57 | 58 | echo "================================" 59 | echo "Beginning iam-common stack delete at $(date)" 60 | aws cloudformation delete-stack --stack-name ${MU_NAMESPACE}-iam-common 61 | echo "================================" 62 | echo "Teardown complete at $(date)" 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Amazon ECS Workshop 2 | 3 | 4 | This is part of an Amazon ECS workshop at https://ecsworkshop.com 5 | 6 | 7 | 8 | ## DEPLOYING MICROSERVICES TO ECS 9 | 10 | https://ecsworkshop.com/images/3-tier-architecture.svg 11 | 12 | 13 | 14 | ## CONFIGURE CLOUDWATCH CONTAINER INSIGHTS FOR YOUR ECS CLUSTER 15 | 16 | 17 | You can use CloudWatch Container Insights to collect, aggregate, and summarize metrics and logs from your containerized applications and microservices. Container Insights is available for Amazon Elastic Container Service, Amazon Elastic Kubernetes Service, and Kubernetes platforms on Amazon EC2. The metrics include utilization for resources such as CPU, memory, disk, and network. Container Insights also provides diagnostic information, such as container restart failures, to help you isolate issues and resolve them quickly. 18 | 19 | ## AMAZON ECS CLUSTER CAPACITY PROVIDERS 20 | 21 | how Capacity Providers can help us in managing autoscaling for EC2 backed tasks, as well as ways to implement cost savings when running Fargate tasks. We will implement two capacity provider strategies in our cluster: 22 | 23 | For a Fargate backed ECS service, we will implement a strategy to deploy that service as a mix between Fargate and Fargate Spot. 24 | 25 | For an EC2 backed ECS service, we will implement Cluster Auto Scaling by increasing the task count of a service beyond the capacity available. This will require the backend EC2 infrastucture to scale to meet the demand, which the ECS cluster autoscaler will handle. 26 | 27 | ## BLUE/GREEN DEPLOYMENTS ON ECS FARGATE 28 | 29 | 30 | Blue/Green deployment is a technique for releasing an application by shifting the traffic between two identical environments running different versions of the same application. Blue/Green deployment is recommended for critical workloads since it mitigates the risks associated with deploying software, such as downtime and rollback capability. 31 | 32 | Traditionally, with in-place upgrades, it was difficult to validate your new application version in a production deployment while also continuing to run your old version of the application. After you deploy the green environment, you have the opportunity to validate it. If you discover the green environment is not operating as expected, there is no impact on the blue environment. You can route traffic back to it, minimizing impaired operation or downtime, and limiting the blast radius of impact. 33 | 34 | ## STATEFUL WORKLOADS ON ECS FARGATE 35 | 36 | we will deploy a stateful workload on ECS Fargate with storage persisting on EFS. There are many reasons for wanting to deploy a stateful workload on containers, with some examples being: 37 | 38 | Content Management Systems like Wordpress, or Drupal. 39 | Sharing static content for web servers 40 | Jenkins Master Nodes 41 | Machine learning 42 | Relational Databases for dev/test environments 43 | 44 | ## LOCAL TESTING USING THE ECS-CLI 45 | 46 | 47 | MORE RESOURCES 48 | Discover more AWS resources for building and running your application on AWS: 49 | 50 | Containers from the Couch - Check out our latest container shows, and learn all about running containers! 51 | More Workshops 52 | Amazon EKS Workshop - This workshop guides you through the process of setting up and using a Kubernetes cluster on AWS 53 | Amazon Lightsail Workshop - If you are getting started with the cloud and looking for a way to run an extremely low cost environment Lightsail is perfect. Learn how to deploy to Amazon Lightsail with this workshop. 54 | Tools for AWS Fargate and Amazon ECS 55 | Containers on AWS - Learn common best-practices for running containers on AWS 56 | copilot-cli - The AWS Copilot CLI is a tool for developers to create, release and manage production ready containerized applications on Amazon ECS and AWS Fargate. 57 | fargate - Command line tool for interacting with AWS Fargate. With just a single command you can build, push, and launch your container in Fargate, orchestrated by ECS. 58 | Terraform - Use Terraform to deploy your docker containers in Fargate 59 | Wonqa is a tool for spinning up disposable QA environments in AWS Fargate, with SSL enabled by Let’s Encrypt. More details about Wonqa on the Wonder Engineering blog 60 | coldbrew - Fantastic tool that provisions ECS infrastructure, builds and deploys your container, and connects your services to an application load balancer automatically. Has a great developer experience for day to day use 61 | mu - Automates everything relating to ECS devops and CI/CD. This framework lets you write a simple metadata file and it constructs all the infrastructure you need so that you can deploy to ECS by simply pushing to your Git repo. 62 | Courses 63 | Microservices with Docker, Flask, and React - Learn how to build, test, and deploy microservices powered by Docker, Flask, React Amazon ECS! 64 | 65 | 66 | -------------------------------------------------------------------------------- /images/web-app-ecs-architecture.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | AmazonAmazonRoute 53Route 53AAFrontend ALBFrontend ALBBackend ALBBackend ALBAvailability ZoneAvailability ZoneAvailability ZoneAvailability ZoneAZAZCCAZAZAZAZBBAvailability ZoneAvailability Zone --------------------------------------------------------------------------------