ECS -project — Hands On

Nivas DevSecOps
6 min readSep 12, 2024

--

Amazon Elastic Container Service (ECS) is a fully managed container orchestration service provided by Amazon Web Services (AWS). It allows you to easily run, stop, and manage Docker containers on a cluster. ECS eliminates the need for you to install, operate, and scale your own cluster management infrastructure. Instead, you can focus on defining and running your applications.

Key concepts related to ECS

Task Definition

A task definition is a blueprint for your application. It defines various parameters, including the Docker image, CPU and memory requirements, network settings, and other configurations.It is used to create tasks, which represent the running containers in your cluster.

Service

A service is a long-running task definition that runs and maintains a specified number of instances of a task definition. It ensures that the desired number of tasks are constantly running in the cluster.Services enable you to define the desired state of your applications, such as the number of tasks, the task definition to use, and the network configuration.

ECS Cluster

An ECS cluster is a logical grouping of tasks or services. It is the compute infrastructure that ECS uses to run your applications. A cluster can span multiple Availability Zones for high availability.

Application Load Balancer (ALB)

An Application Load Balancer is a service that automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, and IP addresses.It plays a crucial role in ensuring that traffic is evenly distributed among the tasks running in your ECS cluster.

High Level Steps

  1. Creating a Cluster using EC2 Launch type
  2. Create a Task Definition File
  3. Create a service
  4. Set up Load Balancer

Steps

  1. Open aws account , and in the search bar type ECS
  2. You will see something like then click on cluster button

3. Select or type all the selected/higlighed options . I have named cluster myCluster but you can name it anything. We are going to use EC2 launch type for our running our container instance .

4. This is going to create a auto scaling template for our cluster . We can practically select any AMI but I have decide to select latest AMI by aws and for sake of saving money I have selected t2.micro instance as this is free under free tier .

6. Rest option we will leave as default and click on create cluster .

7.It will take some time to create cluster . In the meantime, we will create our task definition.

8. Now click on create task definition

9. Click on create task definition , and select the following values .

we will name our task myTask . Again we specify that we want to run our task on EC2 instance .

10. We will select linux as the operating system ,and select awsvpc as the networking model. We will select 0.25 as the vCPU , and 0.25 GB RAM as in t2.micro instance we have 1 vCPU and 1GB ram.

11. Now we have to select image for our container , I have selected inderharrysingh/netflix image , this is being host on the docker hub . You can select any image on the docker or even on the ecr , and as this is a public image , we don’t need to provide any credentials . We have selected the same RAM and CPU specification as we did in case of task.

12. We will keep all other things as default . And Click on create

13. Now both our task and cluster has been created. Its time to create a service to deploy on our cluster and configure load balancer .

14 . Now go back to the cluster , and click on it .

15. Click on create service.

16. We will keep most of the setting default

17. In the family section , we will select the task we have just created and we will keep desired task to 1 , this refer to number of tasks we want to run in this service .

18. Now we will configure the load balancer , scroll down you can find the load balancer option .

19. Select these settings, most of the option are pre filled we just have to specify the name of the target group.

20. Now click on create

21. This will take some time for ALB to be created and service to be started on the cluster.

22. To connect to our application , we have to find the DNS name of the ALB .

23. In the EC2 section , you will find the ALB section at bottom.

24. Click on the Load Balancer and copy the DNS of the ALB we have created and open this in the browser.

25. Now you can view deployed application .

If you dont’ see anything , it is possible that service has not yet been deployed so wait for some time and check again on the browser .

Output

Hope it helps..!

Thank you for reading so far! Before you go:

--

--

Nivas DevSecOps
Nivas DevSecOps

Written by Nivas DevSecOps

Cloud | DevSecOps| AWS ⭐Passionate Cloud and DevOps . 🎯 Like to stay up-to-date with the latest trends and insights.

No responses yet