All Projects → devteds → e9-cloudformation-docker-ecs

devteds / e9-cloudformation-docker-ecs

Licence: other
Docker on Amazon ECS with AWS Fargate using CloudFormation. https://devteds.com/episodes/9-docker-on-amazon-ecs-using-cloudformation

Programming Languages

shell
77523 projects
ruby
36898 projects - #4 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to e9-cloudformation-docker-ecs

Perun
A command-line validation tool for AWS Cloud Formation that allows to conquer the cloud faster!
Stars: ✭ 82 (+5.13%)
Mutual labels:  yaml, aws-cli, aws-cloudformation
ecs composex
Manage, Configure and Deploy your services and AWS services and applications from your docker-compose definitions
Stars: ✭ 79 (+1.28%)
Mutual labels:  aws-ecs, aws-cloudformation, aws-fargate
Awesome Ecs
A curated list of awesome ECS guides, development tools, and resources
Stars: ✭ 2,672 (+3325.64%)
Mutual labels:  aws-ecs, aws-fargate
aws-terraform
AWS & Terraform Rocket Start Guide
Stars: ✭ 53 (-32.05%)
Mutual labels:  aws-cli, aws-vpc
Torchlambda
Lightweight tool to deploy PyTorch models to AWS Lambda
Stars: ✭ 83 (+6.41%)
Mutual labels:  yaml, aws-cli
Iamy
A cli tool for importing and exporting AWS IAM configuration to YAML files
Stars: ✭ 200 (+156.41%)
Mutual labels:  yaml, aws-cli
Ecs Deploy
Powerful CLI tool to simplify Amazon ECS deployments, rollbacks & scaling
Stars: ✭ 541 (+593.59%)
Mutual labels:  aws-cli, aws-ecs
terraform-aws-ecs-fargate-task-definition
AWS ECS Fargate Task Definition Terraform Module
Stars: ✭ 20 (-74.36%)
Mutual labels:  aws-ecs, aws-fargate
aws-ecs-orb
An orb that simplifies deployment to Amazon's Elastic Container Service (ECS). Supports both EC2 and Fargate launch types.
Stars: ✭ 48 (-38.46%)
Mutual labels:  aws-ecs, aws-fargate
cdk-github-actions-runner
Deploy self-hosted GitHub Actions runner to AWS Fargate using AWS Cloud Development Kit (CDK)
Stars: ✭ 89 (+14.1%)
Mutual labels:  aws-ecs, aws-fargate
qaz
qaz—A CLI tool for Templating & Managing stacks in AWS Cloudformation
Stars: ✭ 89 (+14.1%)
Mutual labels:  yaml, aws-cloudformation
aws-sync-routes
Synchronizes the specified route from the main/default route table to all custom route tables in the VPC.
Stars: ✭ 16 (-79.49%)
Mutual labels:  aws-vpc, aws-cloudformation
refmt
Reformat HCL ⇄ JSON ⇄ YAML.
Stars: ✭ 19 (-75.64%)
Mutual labels:  yaml
anabneri
✨ This is a README that appears on the homepage of my profile.
Stars: ✭ 14 (-82.05%)
Mutual labels:  aws-cloudformation
yaml-frontmatter-loader
[DEPRECATED] Yaml frontmatter loader
Stars: ✭ 12 (-84.62%)
Mutual labels:  yaml
ansible-aws-template
A tiny Ansible quick-start for AWS and Dynamic Inventory
Stars: ✭ 12 (-84.62%)
Mutual labels:  aws-cloudformation
python-yamlable
A thin wrapper of PyYaml to convert Python objects to YAML and back
Stars: ✭ 28 (-64.1%)
Mutual labels:  yaml
awscfncli
Friendly AWS CloudFormation CLI
Stars: ✭ 54 (-30.77%)
Mutual labels:  aws-cloudformation
k8s-1abel
Kubernetes YAML/JSON survival kit
Stars: ✭ 21 (-73.08%)
Mutual labels:  yaml
yaml
A Laravel YAML parser and config loader
Stars: ✭ 100 (+28.21%)
Mutual labels:  yaml

Docker on Amazon ECS using AWS CloudFormation & CLI

Devteds Episode #9

Create and run docker container on Amazon ECS using CloudFormation and CLI.

  • Containerize a simple REST API application
  • Use AWS CLI to create Amazon ECR repository
  • Build docker image and push to ECR
  • CloudFormation stack to create VPC, Subnets, InternetGateway etc
  • CloudFormation stack to create IAM role
  • CloudFormation stack to create ECS Cluster, Loadbalancer & Listener, Security groups etc
  • CloudFormation stack to deploy docker container

Episode video link

Episode Video Link

Visit https://devteds.com to watch all the episodes

Terminal Window Logs

Code

mkdir ~/projs
git clone https://github.com/devteds/e9-cloudformation-docker-ecs.git docker-on-ecs
cd docker-on-ecs

Dockerize a simple app

# Run on local
docker build -t books-api ./app/
docker run -it -p 4567:4567 --rm books-api:latest
open http://localhost:4567/
open http://localhost:4567/stat
open http://localhost:4567/api/books

Push Docker Image to ECR

aws ecr create-repository --repository-name books-api
aws ecr get-login --no-include-email | sh
IMAGE_REPO=$(aws ecr describe-repositories --repository-names books-api --query 'repositories[0].repositoryUri' --output text)
docker tag books-api:latest $IMAGE_REPO:v1
docker push $IMAGE_REPO:v1

Create CloudFormation Stacks

aws cloudformation create-stack --template-body file://$PWD/infra/vpc.yml --stack-name vpc

aws cloudformation create-stack --template-body file://$PWD/infra/iam.yml --stack-name iam --capabilities CAPABILITY_IAM

aws cloudformation create-stack --template-body file://$PWD/infra/app-cluster.yml --stack-name app-cluster

# Edit the api.yml to update Image tag/URL under Task > ContainerDefinitions and,
aws cloudformation create-stack --template-body file://$PWD/infra/api.yml --stack-name api

Copy the BooksApiEndpoint value from api stack output on AWS Management Console. Make a request to that URL on browser or any REST client.

Need to deploy app changes?

There 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,

  • 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.
  • With CloudFormation, some prefer create-stack & delete-stack to manage zero-downtime blue-green deployments, not specifically for ECS. ECS does part of this but this is an option
  • 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.
  • A little hack to register a new task definition revision and update the service using CLI. Refer the ./deploy_app.sh script.
# ./deploy_app.sh <CLUSTER NAME> <SERVICE NAME> <TASK FAMILY>
./deploy_app.sh bookstore books-service apis
# One executed, ECS Service update will take a few minutes for the new task / container go live

References

Find the resources and references on https://devteds.com/episodes/9-docker-on-amazon-ecs-using-cloudformation

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].