Serverless Container Operations with AWS Fargate - Usage Patterns for ECS and EKS

Run serverless containers without managing instances. Learn how to choose between ECS and EKS, and optimize costs through task sizing.

How Fargate Works and How It Differs from EC2 Launch Type

Fargate is a serverless compute engine for ECS and EKS. With the EC2 launch type, you manage the provisioning, scaling, and patching of EC2 instances that run your containers, but with Fargate you can leave this management to AWS. When you specify vCPU (0.25 to 16) and memory (0.5 GiB to 120 GiB) in your task definition, AWS prepares the container execution environment. Each task runs in a Firecracker-based isolated microVM, eliminating kernel sharing between tasks and strengthening security isolation. Access to the host OS is impossible, and privileged containers cannot run. Platform versions (ECS) manage the OS kernel and runtime version; specifying LATEST automatically applies the latest stable version.

Choosing Between ECS on Fargate and EKS on Fargate

ECS on Fargate is an AWS-native container orchestration that can be operated simply with three concepts: task definitions, services, and clusters. It provides ALB integration, service mesh via Service Connect, and service discovery via CloudMap out of the box. ECS Exec lets you attach an interactive shell to containers within tasks for production debugging. EKS on Fargate runs Kubernetes Pods on Fargate. Fargate Profiles define namespace and label selectors, and matching Pods are automatically scheduled to Fargate. Choose this when you want to leverage the Kubernetes ecosystem (Helm, Argo CD, Prometheus, etc.) or when standardizing on Kubernetes across multiple clouds. However, EKS on Fargate has limitations: DaemonSets cannot be used, EBS volumes cannot be mounted (EFS is supported), GPU instances are unavailable, and startup is slower than EC2 nodes because an ENI is assigned per Pod.

Cost Optimization

Fargate pricing is pay-per-use based on vCPU-seconds and memory GB-seconds. Proper task sizing is the key to cost optimization. Actual CPU and memory utilization is measured with CloudWatch Container Insights, and the resources of over-provisioned tasks are reduced based on it. Fargate Spot is available at up to a 70% discount off the regular Fargate price, and on interruption the grace period from the SIGTERM signal until the container is forcibly stopped is 30 seconds by default. It's well-suited for interrupt-tolerant workloads like queue-based workers and batch processing. Compute Savings Plans apply across Fargate, Lambda, and EC2, offering up to 50% savings on Fargate usage with a one- or three-year commitment.

Design Best Practices and Pitfalls

A valid matrix of vCPU and memory combinations exists; you cannot specify arbitrary combinations (e.g., 0.25 vCPU only allows 0.5/1/2 GiB). If you don't properly set the health check grace period (healthCheckGracePeriodSeconds), containers with slow startup may be repeatedly stopped and restarted due to health check failures. Ephemeral storage defaults to 20 GiB (max 200 GiB) and is lost on task termination, so EFS or S3 is used for persistent data. The awsvpc network mode is mandatory, and since each task gets an ENI, watch for subnet IP address exhaustion. For workloads running many tasks, provision at least a /19 CIDR or enable ENI Trunking.

Fargate vs. App Runner

App Runner (no longer accepting new customers) is a container service that builds, deploys, and scales automatically from source code or container images. If you already use it, one option is to publish web applications and APIs without VPC configuration or task definitions. Fargate, on the other hand, offers VPC placement, fine-grained security group control, sidecar containers, multi-container task definitions, and EFS mounts for advanced networking and customization. ECS on Fargate suits batch processing, multi-container configurations, and workloads requiring direct access to VPC resources, while steady-traffic web APIs are an option for existing App Runner users. EKS on Fargate is chosen when reusing existing Kubernetes manifests and toolchains.

Summary

Fargate is a serverless compute engine that shifts infrastructure management for container operations to AWS. You can start simply with ECS on Fargate and migrate to EKS on Fargate when Kubernetes is needed. For cost, Fargate Spot and Savings Plans are options, and resource utilization is monitored continuously with Container Insights. Understanding typical pitfalls like subnet IP exhaustion, valid vCPU/memory combinations, and health check settings forms a foundation for stable production operations.

References (Official AWS Resources)

The primary sources for this page are the official AWS website and documentation. Check the official pages below for the latest specifications and pricing.

If this page and the official documentation disagree, treat the official documentation as authoritative.

Share