{"id":20181896,"url":"https://github.com/devteds/e9-cloudformation-docker-ecs","last_synced_at":"2025-08-21T15:31:16.817Z","repository":{"id":48093329,"uuid":"143485203","full_name":"devteds/e9-cloudformation-docker-ecs","owner":"devteds","description":"Docker on Amazon ECS with AWS Fargate using CloudFormation. https://devteds.com/episodes/9-docker-on-amazon-ecs-using-cloudformation","archived":false,"fork":false,"pushed_at":"2022-08-09T21:54:42.000Z","size":13,"stargazers_count":97,"open_issues_count":2,"forks_count":102,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-07T19:02:40.468Z","etag":null,"topics":["aws","aws-cli","aws-cloudformation","aws-ecr","aws-ecs","aws-fargate","aws-vpc","docker","elastic-container-service","yaml"],"latest_commit_sha":null,"homepage":"https://devteds.com","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devteds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-04T00:32:44.000Z","updated_at":"2024-06-25T21:30:33.000Z","dependencies_parsed_at":"2022-08-12T18:31:00.279Z","dependency_job_id":null,"html_url":"https://github.com/devteds/e9-cloudformation-docker-ecs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devteds%2Fe9-cloudformation-docker-ecs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devteds%2Fe9-cloudformation-docker-ecs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devteds%2Fe9-cloudformation-docker-ecs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devteds%2Fe9-cloudformation-docker-ecs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devteds","download_url":"https://codeload.github.com/devteds/e9-cloudformation-docker-ecs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230520391,"owners_count":18238948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-cli","aws-cloudformation","aws-ecr","aws-ecs","aws-fargate","aws-vpc","docker","elastic-container-service","yaml"],"created_at":"2024-11-14T02:37:01.066Z","updated_at":"2024-12-20T01:14:34.947Z","avatar_url":"https://github.com/devteds.png","language":"Shell","readme":"# Docker on Amazon ECS using AWS CloudFormation \u0026 CLI\n\nDevteds [Episode #9](https://devteds.com/episodes/9-docker-on-amazon-ecs-using-cloudformation)\n\nCreate and run docker container on Amazon ECS using CloudFormation and CLI.\n\n- Containerize a simple REST API application\n- Use AWS CLI to create Amazon ECR repository\n- Build docker image and push to ECR\n- CloudFormation stack to create VPC, Subnets, InternetGateway etc\n- CloudFormation stack to create IAM role\n- CloudFormation stack to create ECS Cluster, Loadbalancer \u0026 Listener, Security groups etc\n- CloudFormation stack to deploy docker container\n\n[Episode video link](https://youtu.be/Gr2yTSsVSqg)\n\n[![Episode Video Link](https://i.ytimg.com/vi/Gr2yTSsVSqg/hqdefault.jpg)](https://devteds.com/docker-on-amazon-ecs-using-cloudformation/)\n\nVisit https://devteds.com to watch all the episodes\n\n\n\n\u003e ## Announcement: Course on Kubernetes\n\u003e If you're want to start deploying your containers to Kubernetes, especially on AWS EKS, [check this course on Kubernetes](https://courses.devteds.com/kubernetes-get-started) that walkthrough creating Kubernetes cluster on AWS EKS using Terraform and deploying multiple related containers applications to Kubernetes and more. https://courses.devteds.com/kubernetes-get-started \n\n\n## Terminal Window Logs\n\n### Code\n\n```\nmkdir ~/projs\ngit clone https://github.com/devteds/e9-cloudformation-docker-ecs.git docker-on-ecs\ncd docker-on-ecs\n```\n\n### Dockerize a simple app\n\n```\n# Run on local\ndocker build -t books-api ./app/\ndocker run -it -p 4567:4567 --rm books-api:latest\nopen http://localhost:4567/\nopen http://localhost:4567/stat\nopen http://localhost:4567/api/books\n```\n\n### Push Docker Image to ECR\n\n```\naws ecr create-repository --repository-name books-api\naws ecr get-login --no-include-email | sh\nIMAGE_REPO=$(aws ecr describe-repositories --repository-names books-api --query 'repositories[0].repositoryUri' --output text)\ndocker tag books-api:latest $IMAGE_REPO:v1\ndocker push $IMAGE_REPO:v1\n```\n\n### Create CloudFormation Stacks\n\n```\naws cloudformation create-stack --template-body file://$PWD/infra/vpc.yml --stack-name vpc\n\naws cloudformation create-stack --template-body file://$PWD/infra/iam.yml --stack-name iam --capabilities CAPABILITY_IAM\n\naws cloudformation create-stack --template-body file://$PWD/infra/app-cluster.yml --stack-name app-cluster\n\n# Edit the api.yml to update Image tag/URL under Task \u003e ContainerDefinitions and,\naws cloudformation create-stack --template-body file://$PWD/infra/api.yml --stack-name api\n```\n\nCopy the `BooksApiEndpoint` value from `api` stack output on AWS Management Console. Make a request to that URL on browser or any REST client.\n\n## Need to deploy app changes?\n\nThere isn't a cleaner way to deploy application changes (container) with CloudFormation, especially if you prefer the same image tag (eg: latest, green, prod etc). There are a few different options,\n\n- Use new image tag and pass that as parameter to CF stack (api.yml) to update-stack or deploy. Many don't prefer using new revision number for as tag.\n- With CloudFormation, some prefer create-stack \u0026 delete-stack to manage zero-downtime blue-green deployments, not specifically for ECS. ECS does part of this but this is an option\n- Use ECS-CLI if you like Docker Compose structure to define container services. This is interesting but I am not sure this is really useful.\n- A little hack to register a new task definition revision and update the service using CLI. Refer the `./deploy_app.sh` script.\n\n```\n# ./deploy_app.sh \u003cCLUSTER NAME\u003e \u003cSERVICE NAME\u003e \u003cTASK FAMILY\u003e\n./deploy_app.sh bookstore books-service apis\n# One executed, ECS Service update will take a few minutes for the new task / container go live\n```\n\n\n## References\n\nFind the resources and references on https://devteds.com/episodes/9-docker-on-amazon-ecs-using-cloudformation\n\n- Blog on automation of docker build and ecs deployment - https://spin.atomicobject.com/2017/06/06/ecs-deployment-script/\n- AWS ECS-CLI https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevteds%2Fe9-cloudformation-docker-ecs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevteds%2Fe9-cloudformation-docker-ecs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevteds%2Fe9-cloudformation-docker-ecs/lists"}