AWS Builder Center

Deploying Containerized Applications with AWS Fargate

Learn how AWS Fargate simplifies the deployment and management of containerized applications by allowing developers to run containers without managing the underlying servers.

Introduction

Containerization has become a popular way to develop, package, and deploy applications. Technologies such as Docker allow applications and their dependencies to be packaged into portable containers. However, running containers at scale still requires infrastructure for computing, networking, and resource management.
AWS Fargate provides a way to run containers on AWS without requiring users to manage the underlying servers. It is a serverless compute engine that works with Amazon Elastic Container Service (Amazon ECS) and Amazon Elastic Kubernetes Service (Amazon EKS).
With Fargate, developers can focus on their applications and containers while AWS manages the underlying compute infrastructure.

What is AWS Fargate?

AWS Fargate is a serverless compute engine designed for running containers. Instead of launching and maintaining virtual machines to run containers, users specify the CPU, memory, networking, and other requirements for their workloads.
AWS then provisions the required compute resources automatically.
Fargate can be used with:
  • Amazon ECS – A container orchestration service for running and managing Docker containers.
  • Amazon EKS – A managed Kubernetes service that can use Fargate to run Kubernetes pods.
This makes Fargate particularly useful for applications where developers want the benefits of containers without managing servers.

How AWS Fargate Works

A typical Fargate deployment with Amazon ECS consists of several components.

1. Container Image

The application is packaged into a container image using Docker. The image can be stored in a container registry such as Amazon Elastic Container Registry (Amazon ECR).

2. ECS Cluster

An Amazon ECS cluster provides a logical grouping for the resources used to run containerized applications.
When using Fargate, there is no need to create or manage EC2 instances inside the cluster.

3. Task Definition

An ECS task definition describes how the container should run.
It can specify:
  • Container image
  • CPU and memory requirements
  • Port mappings
  • Environment variables
  • Logging configuration
  • Networking settings

4. ECS Service

An ECS service maintains a specified number of running tasks. If a task stops unexpectedly, ECS can start another task to maintain the desired number of running containers.

5. Fargate

Fargate provides the compute capacity required to run the tasks. Users only need to define the required resources rather than managing the underlying servers.

Example Architecture

A simple web application could use the following architecture:
User → Application Load Balancer → Amazon ECS → AWS Fargate → Container
The application container can be built with Docker and stored in Amazon ECR. An ECS service can then use the container image to launch Fargate tasks.
An Application Load Balancer can distribute incoming requests across multiple running tasks.
This architecture can also be extended with other AWS services such as Amazon RDS for databases, Amazon CloudWatch for monitoring, and AWS Secrets Manager for securely storing sensitive configuration.

Benefits of AWS Fargate

No Server Management

One of the main advantages of Fargate is that developers do not need to manage the underlying EC2 instances.
There is no need to:
  • Provision servers
  • Install operating systems
  • Manage server patches
  • Configure container hosts
  • Manually scale container instances
AWS manages the infrastructure required to run the containers.

Easy Scaling

Fargate works with ECS services and can run multiple copies of a containerized application.
For example, an application can initially run two tasks and scale to additional tasks when demand increases.
This makes it suitable for applications with changing workloads.

Resource-Based Configuration

Instead of selecting a specific server type, users define the CPU and memory required by their containers.
This allows applications to use resources according to their workload requirements.

Improved Isolation

Fargate tasks run in their own isolated compute environments. This provides a useful separation between workloads and reduces the need to manage shared container-host infrastructure.

Integration with AWS Services

Fargate integrates with many AWS services, including:
  • Amazon ECR
  • Amazon CloudWatch
  • Elastic Load Balancing
  • AWS IAM
  • AWS Secrets Manager
  • Amazon VPC
This allows organizations to build complete cloud-native application architectures around their containerized workloads.

Fargate vs Amazon EC2

Both Fargate and EC2 can be used to run containers with Amazon ECS, but they provide different levels of infrastructure management.
FeatureAWS FargateAmazon EC2
Server managementManaged by AWSManaged by the user
Infrastructure setupMinimalRequired
ScalingCan be automated through ECSRequires managing EC2 capacity
OS maintenanceAWS managedUser managed
Container supportYesYes
Infrastructure controlLowerHigher
Fargate is useful when reducing infrastructure management is a priority. EC2 may be preferable when an organization requires greater control over the underlying servers.

When Should You Use AWS Fargate?

Fargate is a good choice for applications that:
  • Are already containerized
  • Need scalable container infrastructure
  • Do not require direct access to the underlying servers
  • Have variable workloads
  • Want to reduce infrastructure administration
  • Need to integrate containers with other AWS services
It can be particularly useful for microservices architectures, APIs, web applications, background workers, and other container-based workloads.

Getting Started with Fargate

A basic Fargate deployment can follow these steps:
  1. Create a Dockerfile for the application.
  2. Build the Docker image.
  3. Push the image to Amazon ECR.
  4. Create an Amazon ECS cluster.
  5. Create an ECS task definition using the Fargate launch type.
  6. Configure CPU, memory, networking, and environment variables.
  7. Create an ECS service.
  8. Deploy the application.
  9. Monitor the running tasks using Amazon CloudWatch.
Once the service is running, ECS manages the desired number of Fargate tasks.

Conclusion

AWS Fargate provides a convenient way to run containerized applications without managing the underlying servers. By combining Fargate with Amazon ECS or Amazon EKS, developers can build scalable container-based applications while reducing the operational work associated with infrastructure management.
For teams that want to adopt containers while keeping infrastructure management simple, AWS Fargate provides a practical serverless approach to running containerized workloads.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article