DEV Community

Cover image for Deploy a container web application with Amazon ECS & Fargate - Hands On
khaled Eltaweel
khaled Eltaweel

Posted on • Updated on

Deploy a container web application with Amazon ECS & Fargate - Hands On

What is ECS in AWS?
ECS stands for (Elastic Container Service) which is a container management service on AWS that supports Docker containers and allows you to manage your containers on clusters.

What is Fargate?
AWS Fargate is a serverless, pay-as-you-go compute engine that lets you focus on building applications without managing servers.

Steps to deploy your application on ECS:

  1. Create a task definition and add your image source.
  2. Create a security group for the cluster
  3. create a cluster
  4. create a service
  5. Visit your website

Let's start our detailed steps journey to deploy our container.

1. Create a task definition and add your image source:

Open your AWS console and search for ECS and click on task definitions then click on create a new task definition

Image description

In the configure task definition and containers step give your task a name then add your container name and image URL.

In this example we will use an image on my docker hub from this Link.

Add your container port that you want the application to run on it, I will use port 80 then go to the bottom of the page and click next.

Image description

In the configure environment, storage, monitoring, and tags step we will choose AWS Fargate as our app environment to run our application on it.

Operating system will be linux.

CPU will be 0.5 vCPU and Memory will be 1GB.

Image description

Click next and review your task details then click create.

2. Create a security group for the cluster

In the search tab, search for EC2 and choose Security Groups from the Network and Security tab and click on create security group.

Image description

Give your security group a name and a description, the security group will have two inbound rules:

The first rule will have an all traffic protocol type and will be running on port 80 and the traffic source will Anywhere-ipv4.

The second rule will have an all traffic protocol type and will be running on port 80 and the source will Anywhere-ipv6.

Then click Create security group.

Image description

3. create a cluster

Go to clusters from the left side nav and click on create cluster.

Give your cluster a name and choose a VPC, in this example I used the default VPC.

Then click create.

Image description

Image description

One thing left to finish the mission! 🤗

4. create a service

Go to the cluster that we have created and go to service tab and create a new service.

Image description

In the deployment configuration tab specify the application type to be a service, and the task definition choose our task definition that we created in the first step, then type your service name.

Image description

In the Networking tab choose a VPC and subnets.

Choose an existing security group and choose our security group the we created the second step.

Image description

Then Click create.

Now go to services tab in the cluster your will find the service exists with an active status.

5. Visit your website

Go to tasks tab in the cluster, you will find a new task has been created click on it.

Image description

The task will be running and you can access the website via public ip address copy and past it in your browser or click on open address and it will open the website.

Image description

Now, welcome on board.

Image description

Image description

Top comments (3)

Collapse
 
ahmedmagdy2511 profile image
AhmedMagdy2511

Thank you so much that was very helpful

Collapse
 
anasalhayen profile image
AnasAlHayen

Well done really great detailed info. keep it up

Collapse
 
amrmohsen64 profile image
Amr Mohsen

Very informative thanks dude