Deploy a Container On AWS ECS Service

Raghav D
4 min readAug 24, 2020

--

Amazon Elastic Container Service is the Amazon Web Service to deploy Docker containers on a scalable cluster. Here we are going to deploy a sample Nodejs app on ECS service.

AWS provides 2 ways to deploy containers on ECS

  1. AWS Fargate
  2. EC2 Instance

Here we are going to deploy in both the ways, here we are using docker images from docker hub public repo

AWS Fargate: It is a is a serverless compute engine for containers that works with both ECS and EKS

Here we are going to create 2 types of clusters on ECS, one cluster is for using fargate, other for EC2 deployment

  1. Create a cluster on ECS
  2. Create task
  3. Run task

Deploy Container using fargate:

  1. Go to AWS ECS service https://ap-south-1.console.aws.amazon.com/ecs/
  2. Crete a cluster → Networking only → Next step
Cluster creation

3. In Next step, mention the cluster name, if you want to create a new VPC, then mark on create vpc, here I have created VPC with 2 subnets in Mumbai region, click on create cluster, here I have create a cluster with name fargateecs

ECS cluster created for fargate

4. Now we are going to create a task from ECS menu

create task → fargate → Next step

Now go to task definition, task name, task role (ecs task execution role), network mode AWSVPC

Go to add containers, container name → Image, mention the other required parameters

here we are going to deploy a nodejs app which runs on port 8080, so we are mentioning here soft limit 128, port mapping 8080 and creating the task

Note: Image: docker pull raghavendradandothkar/nodejs:latest, application runs on port 8080

Now we have created the task. Now go to ECS menu

ECS menu → goto task definition → select task → click on task → goto actions → run the task

select the launch type: fargate, cluster: fargateecs (we have created cluster with the name fargateecs), Number of task 1, clutser VPC (here I have configured my customised VPC), subnet and run the task

Container has deployed

Now we have deployed the container on ECS, Now click on task, here we can find the public IP, open the browser http://IP:8080

http://IP:8080

our Nodejs app deployed successfully on ECS using fargate

Deploy Container using EC2 Instance:

As above we will create a cluster and task and we will execute the task

  1. create a cluster with the EC2 and networking → Next step
  2. mention the cluster name, select instance and number of instance, AMI and root volume, networking (here we are using default VPC) and update required parameters and create cluster

Now we will create a task

Go to ECS console → task definitions → create new task definition → EC2 → Task definition → Task nam → task role (ecs task execution role) → memory and CPU → add container → container name → Image → port mapping (host port : container port) and add → create task

so till now we have create a cluster and task, now we will execute the task as mentioned below

Go to task definitions → select the task →Actions → run

launch type: EC2 → cluster → testec2 → run task

We have deployed the container on EC2 instance successfully, Now go to clusters select respective cluster

Deployed container on EC2 instance

Click on Instance we will get public IP and open browser go to http://IP:8080

nodejs deployed on EC2 Instance

Note: If you face any issues on ports, kindly check your security groups, In this article all ports are enable to single IP

We have deployed nodejs app on ECS successfully

--

--

No responses yet