Deploy a container web application with Amazon ECS & Fargate - Hands On
Tags: aws, ecs, containerapps, cloud
Published: 2023-01-20 12:39:09

**What is ECS in AWS?**
ECS stands for (Elastic Container Service) which is a container management service on [AWS](https://aws.amazon.com/) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kzstsj1hozaab2kdpzm4.png)


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](https://hub.docker.com/r/khaledeltaweel/webapp).

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a6bk9uq8knnob2fsoki1.png)

In the configure environment, storage, monitoring, and tags step we will choose [AWS Fargate](https://docs.aws.amazon.com/AmazonECS/latest/userguide/what-is-fargate.html) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kikxcsp1q8mpp5jtw7nb.png)

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](https://aws.amazon.com/ec2/ec2-get-started/) and choose Security Groups from the Network and Security tab and click on create security group.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bez0y20g9mf2bfc3ud17.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ys4eoqc6wqh0ltceezo9.png)


**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y27aii3ktdi3hefb2fid.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ohgsgek7menq2vdp6nh.png)



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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9q4pzfp8qt2d7oeom3y9.png)



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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/roitervbg5g15isoibpt.png)


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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvzxa3f6o7zxjfhqmc4t.png)


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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6l9c2hw2z0v1ez0x2c5g.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ve6q8o59a8ul5ijvrtu.png)

Now, welcome on board.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/npwlcw6wbma0btrnk66b.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/274b63kx1k3u5g46zyng.png)