Coder Social home page Coder Social logo

gregbt89 / e9-cloudformation-docker-ecs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from devteds/e9-cloudformation-docker-ecs

0.0 0.0 0.0 13 KB

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

Home Page: https://devteds.com

Shell 51.95% Ruby 37.35% Dockerfile 10.70%

e9-cloudformation-docker-ecs's Introduction

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

Announcement: Course on Kubernetes

If you're want to start deploying your containers to Kubernetes, especially on AWS EKS, check this course on Kubernetes 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

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

e9-cloudformation-docker-ecs's People

Contributors

shettigarc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.