AWS Fargate - A Serverless Compute engine for containers
Tags: serverless, cloud, tutorial
Published: 2022-03-03 21:31:17

## DAY 18 - AWS-Fargate -   A Serverless Compute engine for containers- Day Eighteen


[![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2xzqms84df74vxuh4xx.png)![Image fargate](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qu6a1kfdszcfv354cu0i.png)](https://twitter.com/intent/tweet?text=AWS%20Fargate%20-%20A%20Serverless%20Compute%20engine%20for%20containers%20by%20%40anuvindhs%0A%23Serverless%20%23cloud%20%23fargate%20%23AWS%20%0Ahttps%3A%2F%2Fdev.to%2Fanuvindhs%2Faws-fargate-a-serverless-compute-engine-for-containers-5330)
 

[100 days of Cloud on GitHub](https://github.com/anuvindhs/100daysofcloud) - [Read On iCTPro.co.nz](https://ictpro.co.nz) - [Read on Dev.to](https://dev.to/anuvindhs)

------


What if I say, you can deploy container images in the serverless environment in AWS without monitoring or Managing. Do not have to worry about nodes or components, just worry about VCPU and Vmemory for the container for one time. 


You focus on what you are building and operating apps in Elastic container Services or Kubernetes Services. You won’t have the operational overhead of Scaling, Patching, securing, and Managing servers.

Fargate allows you from .25 to 4 VCPU to your individual container and from .5 to 8 GB of RAM. More flexibility in scaling. Fargate does not have natively build storage( persistence storage). You can attach EFS if you want for your container. 

Let’s start with fargate. 

We will configure an AWS VPC, create a cluster,  create a task definition,  create a container image, Deploy container for nginx server – [Check out Pricing](https://aws.amazon.com/fargate/pricing/).

 ![fargate](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fbyr5qhdt5zgifhuna6p.png)


## Tutorial

### Prerequisite 

AWS account

Administrative privileges for the user

A Container image from docker hub or your personal repo
 
## Lets Deploy our first container with Fargate.


- Step 1 – Create a Cluster

 - Go to elastic container services from the AWS Menu
![Image ecs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ltxvnkd1idxjhsc3juue.png)

 - Click on to Create a Cluster  ![Image cluster](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ptk5mor7k2ubdw52owg5.png)
 
 - Select Networking only and click Next step ![Image networking](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dbm0rdn1kyjtzlt712tk.png)
 - Now Give a Name to Cluster – let’s name fargate-cluster for this demo. Also Giving a Tag Name will make the management easier in the future ( a good practice). Tick if you wish to see container insights with CloudWatch. Now Click Create. ![Image name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6fn6jf14d65kv29vunrv.png)
 - Now if click  View Cluster you will be able to see your newly created cluster. If you are using an old dashboard click to Update Cluster or Click edit.
 - Select Default capacity provider strategy as  Fargate_Spot  For this demo as this will be cheaper, Check the pricing model for more info. and click Update.![Image default](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjzho5hpeutdn1yw5xha.png)
 
- Step 2 Create a Task Definition.
 - Task definition is different parameter used to deploy container for ECS. ![Image task](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wavj0ucnt9jfto5yv1bf.png)
 
 - Now Select  Fargate & Click  Next.
![Image next](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yfucz2nq1n80orgt3lro.png)
 
 - Let’s Name the task definition as  Nginx. You can give any name, it’s mainly for your reference
 - Task Role – Optional IAM role that tasks can use to make API requests to authorized AWS services. Create an Amazon Elastic Container Service Task Role in the IAM Console.
 - Task Execution Role –   Click to Create a New Role if you don’t have one already.
 - Now Let’s define the – Task Memory , we will select .5 for the demo & .25 VPC for the Task CPU.
 - Click to Add container, we are going to add a basic container image ![Image cointainer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qz1pww8a90cnr3cdzv1y.png)
 


- Step 3 Adding a container
 - Lets name our Cointaner – nginx.
 - Image – add URL from docker hub, am pulling nginx.
 - Port Mapping –  Expose port 80 for nginx. 
 - keep everything as it is.
 - Now Click  Add & then  Create ![Image nginx](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7j3wl32f38okk660r6wy.png)
 
- Step 4  Deploy a task using task definition.

 - Now Click  **Actions -> Run Task**
 - Make sure you have selected the wright  **Cluster**.![Image fargate2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4t6yqv7d2wfmm3epungt.png)
 
 - And also select the  **VPC** .![Image vpc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pihwjs3p6myr0qznimqc.png)
 
 - Select all **subnets** Available.
 - Now select a **Security Group** with **port 80** open.
 - **Auto-assign public IP** has to be  **ENABLED**.![Image ip](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/khfdqd4lu9cet2xul0wb.png)
 
 - Keep Everything as it is and click  **Run task**.

- Step 5 Wait and See the MAGIC.
 - When the status changes to running hit the Public IP on your browser to see the nginx server running.![Image running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6ozohpx3qk01xxz6nir.png)
![Image nginx](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5oaa6f9le3aaoghvy0qz.png)
 
 ----------

**✅Connect with me on [Twitter](https://twitter.com/intent/follow?ref_src=anuvindhs&screen_name=anuvindhs)
 🤝🏽Connect with me on [Linkedin](https://www.linkedin.com/in/anuvindhs)
🧑🏼‍🤝‍🧑🏻 Read more post on [dev.to](https://dev.to/anuvindhs) or  [iCTPro.co.nz](https://ictpro.co.nz)
💻 Connect with me on [GitHub](https://github.com/anuvindhs)**



{% user anuvindhs %}