This tutorial will guide you through the process of deploying and running Docker containers on Amazon Elastic Container Service (ECS) with AWS Fargate using AWS CloudFormation stacks. To accomplish this, we’ll be creating Elastic Container Registry (ECR) and multiple CloudFormation stacks for groups of resources on the cloud, including VPC, subnets, load balancers, CloudWatch, ECS Cluster, container tasks, and services.
Here are the steps we’ll follow:
- Containerize a simple
REST APIapplication by building aDockerimage. - Use AWS
CLIto create a repository on AmazonElastic Container Registry(Docker Registry). - Push the Docker image to the repository on Amazon ECR.
- Define and run a
CloudFormationstack to createVPCand all network components. - Define and run a CloudFormation stack to create IAM roles.
- Define and run a CloudFormation stack to create ECS Cluster, Load balancer, CloudWatch Log Group, and Security Groups.
- Define and run a CloudFormation stack to deploy the Docker application, including creating a task for the container, a service to schedule the task, a load balancer target group for container services, and a load balancer listener rule for container service.
Upon completing this tutorial, you will be able to create ECS Fargate infrastructure using CloudFormation code, and deploy and execute Docker containers on ECS.
Additional Learning
- If you’re interested in exploring Kubernetes on AWS, be sure check this course: Kubernetes on AWS EKS: Get Started for Developers & DevOps
- And if you’re looking for a solution that’ll help you quickly get your containers on AWS and run at scale, check the AWS App Runner