AWS CDK: Deploying sample application on ECS and EC2
In this post, I will be walking through with the steps you need to deploy a sample ECS application on AWS EC2 with the help of AWS CDK.
I am assuming you have awareness on AWS ECS, AWS CDK, AWS EC2 and EC2 Auto Scaling Group.
- AWS ECS is the container orchestration native platform provided by AWS. If you need more info, please visit the documentation here.
- AWS CDK, which stands for cloud development kit, is an Infrastructure as a code framework, where you can use your own programming language to develop the infrastructure code. I created an AWS CDK — 101 session on youtube available here.
- AWS EC2 provides on-demand compute platform on AWS. You can customize your compute platform based on operating system, CPU, memory, etc. If you need more info, you can check more info here.
- AWS EC2 Auto Scaling helps in automating the scaling behavior of your EC2 instances. If you need a quick overview, you can check my youtube video here.
If you need to deploy a sample web application on ECS with EC2, this is how the typical architecture will look like.
The load balancer receives the request, forwards it to the target groups. The target groups are mapped to the service and task instances. This ensures the request is forwarded to one of the task instances. The task instance serves the request and returns the response.
The task instances will be scheduled on container EC2 instances, which will be governed through EC2 auto scaling group and policy. For this you need to create an EC2 Auto Scaling Group so that EC2 instances can scale-in or scale-out. An ECS service will schedule the task instances on the Auto Scaling Group with the help of this capacity provider.
In ECS, you need to create a capacity provider and map the Auto Scaling Group to it. With capacity provider, you can also configure the scaling…