How to setup Elastic Container Service (ECS) on AWS

Elastic Container Service is a fully managed container orchestration service provided by AWS. It is a choice to run containers on AWS. It supports Fargate to provide serverless compute for containers. Fargate removes the need to provision and manage servers. ECS helps to focus on building and managing applications instead of infrastructure. It is a highly scalable, fast container management service that makes it easy to run, stop, and manage containers on a cluster.

ECS comes with different pricing models. To know about its pricing visit the AWS official page here.

Basic terminologies in ECS.

  1. ECS Cluster: It is a logical grouping of tasks or services.
  2. The Task Definition:  It describes one or more containers (up to a maximum of ten) that form your application.
  3. The Task: It is a runnable unit of a task definition.
  4. Service:  It is used to run and maintain a specified number of instances of a task definition.

In this article, we will create an ECS cluster and deploy a sample Nginx application onto it. We will create a test cluster to understand the cluster setup. You are advised to set up a production cluster with a customized configuration as per the requirement.


  1. AWS Account(Create if you don’t have one).
  2. Basic understanding of IAM Role(Click here to learn about IAM). 
  3. Basic understanding of VPC(Click here to learn about VPC)

What will we do?

  1. Login to AWS(Create if you don’t have one).
  2. Create a Cluster
  3. Create a Task Execution IAM Role
  4. Create a Task Definition
  5. Create a Service
  6. Access the Task we created
  7. Delete the Cluster

Login to AWS

Click here to go to the AWS Login page and enter your credentials.

Login Page

Once you login into the account, you will see the main AWS Management Console as follows.

AWS Management Console

Create a Cluster

To go to ECS, click on services in the top left of the screen and under Containers, click on Elastic Container Service.

Go to ECS

You will see the main dashboard of ECS as below. Click on "Clusters" in the left panel.

ECS dashboard

Since I have not created any cluster we see nothing in the list. Create your first cluster click on the "Create Cluster" button.

Create a Cluster

Here, select the "EC2 Linux + Networking" option and click on the "Next step" button.

Select cluster template

Give a name to the cluster, select EC2 instance type. EC2 instances in the cluster will get created of the type we select. Select the provisioning model of EC2 instances to be created. Specify other configurations as per your requirement.

Configure Cluster

You can either create a new PC or choose an existing one. If you are not aware of VPC and networking and would like to know more about it I would recommend you go through the article here.

Configure Cluster Networking

You can specify tags if you want or you can keep it empty as it is an optional configuration. Click on the "Create" button which will create a cluster for you.

Create a cluster

This will take a few minutes and once the cluster has been created you can see the status as  "ECS Status -3 of 3.. "on the same page. Click on the "View Cluster" button to go to the cluster.

Successful cluster creation

Create a Task Execution IAM Role

Before you proceed with the further configuration you will need a role that will be used for task execution. So go to IAM and create a new role with the following policy. Click here if you are not aware of IAM and would like to learn more about it.

Create a Role: ecsTaskExecutionRole with the following policy.

    "Version": "2012-10-17",
    "Statement": [
            "Effect": "Allow",
            "Action": [
            "Resource": "*"

Once you create a Role you will see it as follows in the IAM console.

IAM Role

Create a Task Definition

If you are ready with the IAM Role, you can now proceed with creating a task definition.

Till this point, you just have an empty cluster that does not have your containerized application running into it.

The next step is to create a task definition. To create your first task definition click on "Task Definitions" in the left panel under "Clusters".

Cluster overview

Here click on the "Create new Task Definitions" button.

Create a Task definition

On this page select, the launch type as "EC2 And then click on the "Next" step button". 

Select launch type

Remember we created an IAM role in the previous step? Now, we need to specify the Role we created under the Task role. Give a name to the task definition.

Configure task definition

When you scroll down a bit you will see the "Add container" button, click on it and you will see a new screen popping up as follows.

On this screen given a name to the container, specify the image to be used for the container. You can also specify memory limits, port mappings, health checks. If you're done with the configuration click on the "Add" button.

Add container

Specify "Task memory" and "Task CPU" that will be used by the task.

Specify resources

Now you are ready with the basic and mandatory configuration for the task, click on the "Create" button which will create a task definition.

Create a task

You will see the message as "Created Task Definition successfully".

Successful task creation

Create a Service

Till this point, we have a cluster and task definition. The next step is to create a service. Go back to the cluster we created and under the Service tab click on the Create button to create a Service.

Cluster overview

Choose the launch type as EC2,  select the task definition we created, you can choose the Cluster name from the drop-down option, Even name to the service we are creating, specify the number of tasks as 2 which will create 2 copies of your application.

Configure a Service

Keep the rest of the configuration as is under deployments and task placement. Tags are optional so it is not mandatory to specify tags. Click on the "Next step" button to proceed further.

Configure a service

If you have any load balancer then you can select it to route the external traffic to your application through it. Click on the "Next step" button.

Configure a Service

If you do not want your service to be scaled then proceed with the default configuration as "Do not adjust the service's desired count".

Set ASG if required

Review the configuration that we have just made for the service to be created click on the "Create Service" button.

Review and create a Service

You see the status as "ECS Service status- 1 of 1 completed" if the service has been created successfully.

Successful service creation

Access the Task we created

Go back to the cluster and under the "Tasks" tab now you can see 2 tasks are running. These tasks contain your application.

Click on one of the tasks to know more about it.

Check Tasks

Since we have not specified any load balancer we cannot access the application from the external world on a specific link. Because of this, we would need to access our tasks on their individual external links.

Under Network bindings, you can find the external link of the task. This particular task will only be accessible from the link available here. Copy the link to test if the application, Nginx, that we had specified in the task definition is up and running.

Get an  external link from the task

Go to the browser and hit the link we copied in the previous step. You can see the default page of Nginx. This means our application, Nginx, has been successfully deployed. 

Access the task

Delete the Cluster

If you no longer need your cluster you can delete it with a single click. Go back to the cluster and click on the Delete Cluster" button.

Confirm the deletion action by entering "delete me" in the text field and click on the "Delete" button. This will permanently delete the cluster and once deleted you can not recover it. So be careful while deleting the cluster if you are working on real-time applications.

Delete the task


In this article, we saw the steps to create a cluster, task definition and a service. The steps we saw can be used to create a test cluster. If you want to create a Cluster with the real-time application, you need to be more specific about the configurations we saw. 

Share this page:

0 Comment(s)