Blog

Blog

AWS Fargate – A Compute Engine For ECS

AWS Fargate

AWS Fargate

Introduction:

AWS Fargate is a serverless compute engine for containers that allows you to run containerized applications without having to manage the underlying infrastructure. With Fargate, you can focus on developing and deploying your containerized applications, while AWS takes care of the underlying infrastructure such as managing the servers, scaling, and security.

Fargate works with Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS), which are both managed container orchestration services. ECS allows you to easily deploy and manage containers on a cluster of EC2 instances, while EKS provides a fully managed Kubernetes environment.

With Fargate, you only pay for the resources your containers use, rather than paying for the entire EC2 instance. This makes it a cost-effective solution for running containerized applications. Fargate also provides a secure environment for running containers by isolating each container using AWS VPC networking and providing integration with AWS security services.

Overall, Fargate is a great choice for developers who want to focus on building and deploying their applications without having to worry about the underlying infrastructure. It provides a scalable, cost-effective, and secure environment for running containers.

What is AWS Fargate?

AWS Fargate is a compute engine for Amazon Elastic Container Service (ECS) that allows you to run containers without having to manage the provision, configure & scale clusters of VMs that host container applications (underlying EC2 instances). Fargate eliminates the need to provision and manage the EC2 instances that host your containers, making it easier to scale and manage containerized applications.

AWS Fargate eliminates the need for users to manage the EC2 instances on their own. In fact, users don’t need to use EC2 instances at all. Fargate itself will act as compute engine. It lets you focus on elements like designing and constructing your application instead of managing the infrastructure that runs them. With Fargate launch type, all you need to do is package your apphttps://www.datavalley.ai/lication in containers, specify the memory and CPU requirements, define IAM policies & launch your application.

AWS Fargate also makes it easy to scale your applications. Once you define all your application requirements, AWS Fargate manages all the scaling and infrastructure needed to run your containers in a highly-available manner. It seamlessly integrates with Amazon ECS & EKS, and launches and manages your containers for you.

Now how does this entire process of launching containers without having to maintain underlying servers work? 

image

Containerization has transformed cloud architecture over the past few years, allowing businesses to build, deploy & manage applications at a faster rate. And the momentum behind containers certainly is not showing any signs of slowing down. There are a plethora of container & container orchestration services that are available today. Most of them, however, still require you to configure and manage clusters of virtual machines for the containers to run. This is where AWS Fargate comes into the picture. Learn more about Amazon Web Services with AWS Training.

In this article, we will be learning about AWS Fargate, a serverless computing platform for containers. The topics which we will be covering in this article are as follows:

This article focuses on the following pointers:

  1. What is AWS Fargate?
  2. Need For AWS Fargate
  3. Working Of Fargate
  4. Demo: Fargate in Action

Let’s get started!

Need For AWS Fargate

When container services still didn’t exist, users used to launch their applications on virtual machines. In the AWS cloud, they deployed applications on EC2 instances. They packaged their application with OS into what we call an Amazon Machine Image(AMI) and then run it on an AWS EC2 instance.

Then docker introduced containers, and people started deploying their applications on these containers. Containers resemble VM. One major difference is that, unlike VMs, containers share the host system’s kernel with other containers. The diagram below will make it more clear.

image

So, as these containers started becoming more and more popular, people started using them on a huge scale. The number of containers in an EC2 instance increased, which in turn increased the number of instances. AWS then launched Amazon Elastic Container Service(ECS).

But what is ECS service? Amazon Elastic Container Service (Amazon ECS) is a highly scalable, high-performance container orchestration service. Amazon ECS reduced some overhead that users had to manage. However, users still had to manage underlying instances that hosted container applications.

This gave AWS the idea to come up with one service that could handle the underlying virtual machines while users can focus on building their applications. The said service is AWS Fargate.

This tutorial on AWS Fargate will help you understand how to run containers on Amazon ECS without having to configure & manage underlying virtual machines.

Fargate provides two ways to run containers:

  • Fargate Task: A Fargate task is a single container or a group of containers that runs on Fargate. You can use the ECS task definition to define the container images and their configurations, and then run the task on Fargate.
  • Fargate Service: A Fargate service allows you to run multiple tasks simultaneously and ensures that a specified number of tasks are running at all times. This can be useful for running applications that require multiple containers or for running tasks that need to be scaled up or down.

With Fargate, you no longer have to provision, configure, or scale the EC2 instances that your containers run on. Instead, you can focus on building and deploying your containerized applications and let Fargate take care of the underlying infrastructure. Additionally, with the integration of Fargate with other AWS services such as Elastic Load Balancing, Auto Scaling, and CloudWatch, it’s easy to set up and manage your containerized applications, scaling them automatically to handle changing loads.

Fargate also supports running containerized applications that require custom or non-default network configurations, such as task networking, host networking, and AWS App Mesh, which is a service mesh that makes it easy to monitor and control microservices.

One use case that is common and benefits greatly from using Fargate is serverless container management, this means that the customer only pays for the resources used during the container execution, and not for any idle time.

Working On AWS Fargate

Before we see the working of AWS Fargate, let’s take a look at some general terms that you encounter frequently when you are dealing with AWS Fargate.

Container: A Docker container is a standardized unit of software development, containing everything that your software application needs to run code, runtime, system tools, system libraries, etc. These containers are created from a read-only template called a container image.

Container Image: Images are typically built from a docker file which is a plain text file that specifies all of the components that are included in the container. These images are stored in a registry from which they can be downloaded & run in the container.

image

Task Definitions: The task definition is a text file, in JSON format, that describes one or more containers that form your application. You can think of it as a blueprint for your application.

Task: A task is the instantiation of a task definition within a cluster. You have the option to specify the number of tasks that will run on your cluster.

Clusters: A cluster is basically the logical grouping of resources that your application needs. If you use the Fargate launch type with tasks within clusters then Amazon ECS manages your cluster resources. If you use the EC2 launch type, then your clusters will be a group of Amazon EC2 container instances that you manage.

image

Now we are ready to venture ahead. The diagram below gives you a rough idea of how to deploy your application on ECS using AWS Fargate.

image

Let’s try to understand the contents of the above image. First, you need to build a container image that suits your application and then store it on a registry. Then you choose a container orchestration service, either Amazon ECS or Amazon EKS, and assign resources to your application. Once you have done that you need to create a cluster to group all those assigned resources. This is when you choose the AWS Fargate launch type. Now AWS Fargate will launch & run all your containers. It manages all the underlying infrastructure and clusters for you. It also seamlessly scales your application needs without you having to bother about it.

Now, let’s go ahead and deploy a simple web application on Amazon ECS using the AWS Fargaet launch type.

AWS Fargate In Action

Follow the below steps to deploy a simple web application on Amazon ECS using the AWS Fargate launch type. 

Note: Make sure you are in the AWS Region where AWS Fargate is available (You can choose N.Virginia).

Step 1: On the Amazon Elastic Container Service console click on the ‘Get Started’ option. 

image

You will be taken to a page where it says “Getting Started with Amazon Elastic Container Service (Amazon ECS) using Fargate”

image

Step 2: Create a container definition. You can always choose preloaded ones if you have just started using AWS Fargate.

image

Step 3: Create a task definition. You can use the sample task definition or optionally rename the task definition and edit the resources used by the task (such as the Task memory and Task CPU values) by choosing Edit. 

image

Step 4: Configure a service that launches and maintains a specified number of copies of the task definition in your cluster. You can use the preloaded service definition or optionally rename the service or review and edit the details by choosing Edit.

image

Step 5: As the final step you need to configure the cluster. Name your cluster, and then Amazon ECS takes care of the networking and IAM configuration for you. Then review what you have done till now and click on Create to finish.

image

That’s it! Your simple web application should be up and running.

Now if your service is a web-based application like the one we just launched, you can view its contents with a web browser.

image
image
image
image
image
image
image
image

Step 6 (Optional): Look for the IPv4 Public IP address in the network section of your service & enter that in your web browser. You should see a webpage that displays the web application that you just launched.

image

Now click on Amazon ECS clusters and select the running service and click on the delete cluster option, enter ‘delete me’ and delete.

image

Hence created cluster was deleted.

image

Now you know how to use AWS Fargate launch type to launch containers on Amazon Elastic Container Service. Go ahead and explore. 

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare

Subscribe to Newsletter

Stay ahead of the rapidly evolving world of technology with our news letters. Subscribe now!