English

Share with friends

Note

Welcome to our comprehensive guide on AWS Fargate! In this guide, we'll take you through the exciting world of AWS Fargate and explore its capabilities.

What is AWS Fargate — A Comprehensive Guide cover image

Welcome to our comprehensive guide on AWS Fargate! In this guide, we'll take you through the exciting world of AWS Fargate and explore its capabilities.

So, what exactly is AWS Fargate? Imagine a magical technology that allows you to run your containers without worrying about the underlying infrastructure. That's exactly what Fargate is! It's like having your own personal genie that takes care of all the nitty-gritty details for you.

So let's explore AWS, starting with AWS Fargate.

What is AWS Fargate?

AWS Fargate is a serverless compute engine that lets you run containers without having to manage servers or clusters.

To put it another way, Fargate eliminates the need to provision, configure, or scale virtual machine clusters in order to execute containers. Choosing server kinds, deciding whether to scale your clusters, or optimizing cluster packing is no longer necessary (or painful).

Adding the cherry to the cake, Amazon's Fargate is compatible with both Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS). This means that you can use Fargate with your existing ECS or EKS deployments, or you can create new deployments that use Fargate.

AWS Fargate will be a better choice for you if:

  • You use containers for your applications,
  • You have a microservice architecture,
  • You are already using ECS and do not wish to have to provision, configure, or scale clusters of virtual machines to run containers.
  • You no longer want to take on the responsibility of determining the appropriate size, scaling, patching, and updates for your container runtime or EC2's.
  • You want to run your tasks and pods without thinking about built-in server capabilities

If your application meets these criteria, congrats then Fargate can be a good way to simplify your container management and reduce your costs.

How Does AWS Fargate Work?

To use Fargate, you create a Fargate task definition. Now, a task definition specifies the container image that you want to run, and the amount of memory and CPU that you want to allocate to the container, and any other configuration options that you need.

Then, you create a Fargate service, which specifies the number of tasks that you want to run and the task definition that you want to use. The task definition is actually a JSON-formatted text file.

It includes one or more container definitions, as well as metadata such as the task role, logging configuration, and networking details

Fargate jobs (pods) operate in their own kernels, offering a safe and secure computing environment. As a result, there is an isolated workload and increased security.

To deploy a container image using AWS Fargate, follow these steps:

  1. Build a container image: Create a Dockerfile.

  2. Host the container image: You have multiple options for hosting your container image. Two common choices are:

    • Amazon Elastic Container Registry (ECR)
    • DockerHub
  3. Choose an orchestration service: You need to decide whether to use Amazon Elastic Container Service (ECS) or Amazon Elastic Kubernetes Service (EKS) as your orchestration service.

  • Amazon ECS: For ECS, you can choose the Fargate launch type, which means your containers will run on Fargate without the need to manage the underlying infrastructure.
  • Amazon EKS: EKS also supports running containers on Fargate, so you can choose the Fargate launch type for your Kubernetes pods.
  1. Create a Cluster with AWS Fargate: If you are done choosing between ECS or EKS as your orchestration service, you can create a cluster with Fargate as the launch type.
  • For ECS: In the ECS console, create a new cluster and select the Fargate launch type. Configure the cluster settings, such as VPC, security groups, and task execution roles.
  • For EKS: In the EKS console, create a new cluster and configure the cluster settings, including VPC, subnets, and security groups. During cluster creation, choose the Fargate profile option to enable running pods on Fargate.

Why the above steps?
This creates the necessary infrastructure and sets up the cluster to use Fargate as the compute engine for running your containers.

AWS Fargate Launch Type

The last step here is to launch an application using the Fargate launch type in AWS, follow these steps:

  1. Containerize your application: Package your application into containers.

  2. Specify CPU and memory requirements: Define the CPU and memory resources that your application requires to run optimally.

  3. Establish IAM and networking policies: Set up the IAM roles and permissions to control access to your application and its resources.

Note

Additionally, configure networking policies, including defining the network mode as 'awsvpc' for each Fargate task. This makes sure that each task has its own elastic network interface.

  1. Start the application: Once you have containerized your application, specified resource requirements, and configured IAM and networking policies, you can launch your application using the Fargate launch type.

Pricing of AWS Fargate

The cost of AWS Fargate is determined by the amount of vCPU, RAM, operating systems, CPU architecture, and storage1 resources consumed, rounded to the nearest second, from the moment you begin downloading your container image until the Amazon ECS Task or Amazon EKS2 Pod terminates.

Prices are determined by the second, with a one-minute minimum. The duration is determined, rounded to the nearest second, from the moment you begin downloading your container image (Docker pull). Billing for Windows containers is done on a per-second basis with a 15-minute minimum.

Although the Fargate Spot option can save customers up to 70% off of usual prices, it works best with interruptible applications.

Unexpected Fees: If your containers transport data or use other AWS services, you can be charged more. You are charged for CloudWatch consumption, for instance, if your containers use Amazon CloudWatch Logs for application logging.

Basic Components of Fargate

With Fargate 1.4, you can specify custom resource configurations for your containers, allowing more fine-grained control over CPU and memory allocation. You can define the exact CPU units and memory values required by your application, rather than selecting from predefined task sizes. This flexibility helps optimize resource allocation and cost.

Source

In the above image, the components are defined as such that Fargate takes care of ECS agent, Docker Agent, and ECS AMI all by itself (if using ECS to begin with) so you don't have to manage those configurations by yourself.

A basic level of AWS Fargate Components includes:

  1. Clusters: Logical groupings of tasks or services that isolate applications. Fargate manages cluster resources.

  2. Task Definitions: JSON files describing one or more containers forming an application. They specify parameters such as OS, containers, ports, and data volumes.

  3. Tasks: Instantiations of task definitions within clusters. Tasks represent running instances of applications.

  4. Services: Amazon ECS services maintain a desired number of tasks simultaneously. If a task fails, the service scheduler launches a replacement to maintain the desired number.

Source

Above is a diagrammatic representation of services with and without Fargate.

AWS EKS with Fargate

Through the use of controllers created by AWS using the upstream, extendable approach offered by Kubernetes, Amazon EKS combines Kubernetes with Fargate. Having said that, you should keep in mind that EKS can also be used without Fargate, in fact, mostly AWS EKS is used without Fargate.

EKS with Fargate

Uses Fargate to manage the underlying infrastructure. This means that you don't have to worry about provisioning or managing EC2 instances. More points to consider:

  • Simple to use — You can deploy your containers with a few simple commands.
  • Cost-effective — Fargate is a cost-effective way to run containers, especially for workloads with variable demand.
  • Limited flexibility — You can't choose the specific EC2 instance type or region where your containers run.
  • Not as widely used — Fargate is not as widely used as EKS without Fargate, so there may be fewer resources available, such as documentation and tutorials.

EKS without Fargate

Uses EC2 instances to manage the underlying infrastructure. This gives you more flexibility in terms of the instance types and regions you can use. More points to consider:

  • More complex to use — You need to have a good understanding of Kubernetes and EC2 instances in order to use EKS without Fargate.
  • Not as cost-effective — EKS without Fargate can be more expensive than EKS with Fargate, especially for workloads with low demand.
  • Widely used — EKS without Fargate is more widely used than EKS with Fargate, so there are more resources available, such as documentation and tutorials.

Noteworthy Points about EKS with Fargate

  1. Amazon EKS integrates with Fargate using controllers built by AWS, allowing Kubernetes Pods to be scheduled on Fargate.
  2. Fargate profiles control which Pods start on Fargate and how they run, defined as part of the Amazon EKS cluster.
  3. When a Pod meets the criteria for running on Fargate, the Fargate controllers recognize, update, and schedule the Pod onto Fargate.

In a nutshell, AWS EKS with Fargate and AWS EKS without Fargate are both managed AWS Kubernetes services (unlike ECS), but they have different ways of managing the underlying infrastructure.

Pros & Cons of AWS Fargate

AWS Fargate offers a great serverless experience for container deployment, simplifying resource management. But not all good things come with ease, following are some pros and cons of using AWS Fargate.

Pros of Fargate

  1. Easy to Use: It eliminates the need to provision and manage the underlying infrastructure.

  2. Scalability: It provides automatic scaling capabilities, it can also quickly scale up or down based on demand, hence high availability and performance.

  3. Security: There are some built-in security features, like VPC isolation, encryption at rest and in transit, and IAM roles integration.

Cons of Fargate

  1. Limited Customizability: Since Fargate abstracts away the underlying infrastructure, you may not be able to customize the underlying host environment. This can be a drawback for many.

  2. Vendor Lock-In: If you adopt Fargate, you become tightly integrated with the AWS ecosystem. Good luck with that. If you plan to miawgrate to another cloud provider or manage containers on-premises it will require significant changes to your architecture and configuration.

Leaving thoughts

Now armed with this comprehensive guide, you have the knowledge and tools to make the most of AWS Fargate.

So, go ahead and unlock the potential of serverless container computing with AWS Fargate, deploy apps and manage your applications in the cloud, run into errors, and debug them. But most importantly, have fun.

Happy Fargetting!

Share with friends

Priyansh Khodiyar's profile

Written by Priyansh Khodiyar

Priyansh is the founder of UnYAML and a software engineer with a passion for writing. He has good experience with writing and working around DevOps tools and technologies, APMs, Kubernetes APIs, etc and loves to share his knowledge with others.

Further Reading

Life is better with cookies 🍪

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt out if you wish. Cookie Policy