Nginx on ECS EC2 type in CloudFormation
Hi,
I was doing some testing with ECS and here I wanted to share with you some insights regarding this matter. As we all know there are 2 ways to implement ECS:
- ECS FARGATE — you pay for what you use, you run containers without EC2 instances.
- ECS EC2 — you pay for EC2 capacity, you are deploying EC2 instances for that.
A comparison can be found here: https://containersonaws.com/introduction/ec2-or-aws-fargate/
Here I want to show you how to imlement a simple Nginx on EC2 type of EC2. For that we need:
- ECS cluster
- ECS task definition — configuration for your containers (Docker image, cpu and so on…)
- ECS service — run a required number of tasks, you can look at it as a deployment kind of type.
- Autoscaling group
- Load Balancer
- All needed roles for each of the services.
Once we have all of that we can create our CloudFormation template. Here I am using a simple Nginx image, and I am running it in my default VPC and subnets. So once you want to use this template, you need to:
- change capacity number of instances.
- use the correct subnets.
- use the correct VPC.
Once we deployed it, our task is running well: