DEV Community

Cover image for Setup containerized Application in AWS ECS - Part 2/3
Camille He
Camille He

Posted on

Setup containerized Application in AWS ECS - Part 2/3

In the previous Part 1/3, I introduced how to setup a MYSQL database in AWS RDS. Now, we will dive into next topic - Setup ECS Cluster in AWS ECS.

Amazon Elastic Container Service (Amazon ECS) is a fully managed container orchestration service that helps you easily deploy, manage, and scale containerized applications. The article will focus on the ECS services and how them work together to manage your containerized application in the Cloud.

⚓ Amazon ECS Concepts

Here is the architecture diagram of the entire project.

The AWS resources in green box are created in this part, which include:

ECS Cluster & ECS Capacity

An Amazon ECS cluster is a logical grouping of tasks or services. There are two capacity options: EC2 and Fargate. In this project, I setup ECS Cluster on EC2 type. You can find a article that talks about the differences between ECS and Fargate at the bottom of article.

Capacity Provider

A capacity provider defines the cluster capacity that Amazon ECS scales up and down of the infrastructure you specify. For Amazon ECS on Amazon EC2, a capacity provider consists of a capacity provider name, an Auto Scaling group.

Amazon EC2 Auto Scaling

As we use Amazon EC2 instances for ECS capacity, I use Auto Scaling groups to manage the Amazon EC2 instances registered to ECS cluster. Auto Scaling ensure that we have the correct number of Amazon EC2 instances available to handle the load for our application.

Launch Template

A launch template contains the configuration information to launch an instance in EC2 Auto Scaling, including the ID of the Amazon Machine Image (AMI) and provides full functionality for Amazon EC2 Auto Scaling.

SNS Topic & Lambda Function

On the right top of the diagram, we setup a SNS topic and Lambda function to automate container instance draining in Amazon ECS. It's not mandatory for the whole project, but good to have in a real world project. I won't dive into the details here, but go through the blog if you're interested the topic.

Terraform Project

Same as before, the AWS resources are defined using Terraform. Here is the GitHub source code

Walk through the README documentation in above GitHub repository, and setup local environment if you want to deploy these AWS resources from local machine, or you can use GitHub Actions workflows.

After done, validate the setup is successful from ECS Console. Your ECS Cluster must have 1 registered container instance as the below picture shows.

Next to Setup containerized Application in AWS ECS - Part 3/3

📚 References

Always appreciate for your ideas and comments. Thanks for reading! 😄

Top comments (0)