Why AWS Fargate?

Sunil V
5 min readApr 29, 2020

--

A company needs to develop an Application. In order to do so, the developer will set up an environment with a server installed in it. Once the application is developed, it needs to be tested by the tester. Now the tester will again set up an environment from the scratch to test the application. Once the application testing is done, it will be deployed on the production server. Again the production needs an environment with a server installed on it so that it can host the application. If you see the same environment setup is done thrice and There could be a version mismatch in different setups.

Write all dependencies in one file(i.e Docker image) to run the application. Now every team downloads this image and runs and tests it. To run this container you have to install docker-engine in the system. Now the problem is solved. Maintaining the containers is very easy because of less number of containers. Your application became viral so you decided to divide your application into microservices and make it into containers. Now the number of containers is large so the maintainence is difficult because we can’t deploy all containers in one single system.

Now we have to buy extra systems and install docker and maintain systems. We have to check containers healthy and systems healthy. Based on application requests we need to increase and decrease systems and containers. Are you searching for a solution to avoid these problems? The simple solution is “AWS Fargate”.

AWS Fargate is a technology that you can use with Amazon ECS to run containers without having to manage servers or clusters of Amazon EC2 instances. With AWS Fargate, you no longer have to provision, configure, or scale clusters of virtual machines to run containers. This removes the need to choose server types, decide when to scale your clusters or optimize cluster packing.

When you run your tasks and services with the Fargate launch type, you package your application in containers, specify the CPU and memory requirements, define networking and IAM policies, and launch the application. Each Fargate task has its own isolation boundary and does not share the underlying kernel, CPU resources, memory resources, or elastic network interface with another task.

If you did not get anything. We go through step by step and discuss how to launch our containers in Fargate. By using Task definition, we specify the container image and its resources and limits. Amazon ECS task definitions for Fargate require that you specify CPU and memory at the task level. Although you can also specify CPU and memory at the container level for Fargate tasks, this is optional.

Do you have a doubt about how can Task definition pull the image from Docker or ECR? By using Task execution role we can achieve that. What does the Task execution role do? The Amazon ECS container agent, and the Fargate agent for your Fargate tasks, make calls to the Amazon ECS API on your behalf. The agent requires an IAM role for the service to know that the agent belongs to you.

Do you think about how can container access AWS resources? By using Task Role you can achieve that. The Task Role is used when code running inside the container needs access to AWS resources. This is equivalent to the instance profile if the code was running directly on an EC2 instance.

By using services you can run multiple instances of Task Definition. An Amazon ECS service enables you to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster. If any of your tasks should fail or stop for any reason, the Amazon ECS service scheduler launches another instance of your task definition to replace it in order to maintain the desired number of tasks in the service.

Placing services in different availability zones you can achieve high availability. To distribute the traffic, you can use ELB. By using private subnets you can provide more security to containers. By placing ELB in public subnets you can serve the application to the outside world.

Application getting more number of requests a few times and application getting less number of request at some times. In these situations now we do not worry about increasing the containers why because Fargate takes care by using auto-scaling. We do not worry about increasing the number of systems or decreasing the number of systems. Also, we don’t want to install Docker in systems.

You can configure the containers in your tasks to send log information to CloudWatch Logs. This allows you to view the logs from the containers in your Fargate tasks. The awslogs log driver configures your Fargate tasks to send log information to Amazon CloudWatch Logs.

AWS Fargate pricing is calculated based on the vCPU and memory resources used from the time you start to download your container image until the Amazon ECS Task, rounded up to the nearest second.

For example, your service uses 5 ECS Tasks, running for 10 minutes (600 seconds) every day for a month (30 days) where each ECS Task uses 1 vCPU and 2GB memory.

Monthly CPU charges

Total vCPU charges = # of Tasks x # vCPUs x price per CPU-second x CPU duration per day (seconds) x # of days

Total vCPU charges = 5 x 1 x 0.000011244 x 600 x 30 = $1.01

Monthly memory charges

Total memory charges = # of Tasks x memory in GB x price per GB x memory duration per day (seconds) x # of days

Total memory charges = 5 x 2 x 0.000001235 x 600 x 30 = $0.22

Monthly Fargate compute charges

Monthly Fargate compute charges = monthly CPU charges + monthly memory charges

Monthly Fargate compute charges = $1.01 + $0.22 = $1.23

Fargate Advantages:

  1. Installation of Docker in Systems
  2. Do not require to check if the container is healthy or not
  3. Server management is abstracted to vendor
  4. Pay-as-you-go model where you only pay for what you use
  5. Automatically scalable and highly available.
  6. Right-sized resources with flexible pricing options
  7. There is no over-provisioning and paying for additional servers.
  8. Fargate ensures that the infrastructure your containers run on is always up-to-date with the required patches
  9. Secure isolation by design
  10. Rich observability of applications

Now Fargate Supports EKS also.

I hope now you have a better understanding of AWS Fargate. So far we have discussed the real problem scenarios and how can we solve these problems by using AWS Fargate. And we discussed key terms of Fargate and advantages. Do you have any doubts about this, feel free to reach out to us at Vitwit.

--

--

Sunil V

Software Developer | AWS Solution Architect Certified at GYTworkz