Jonatan Matajonmatum.com
conceptsnotesexperimentsessays
© 2026 Jonatan Mata. All rights reserved.v2.1.1
Concepts

AWS Fargate

Serverless compute engine for containers that eliminates server management, allowing Docker container execution paying only for consumed resources.

evergreen#aws#fargate#serverless#containers#docker#ecs

What it is

AWS Fargate is a serverless compute engine for containers that works with ECS and EKS. It completely eliminates the need to provision, configure, and manage EC2 instances. You define CPU and memory for your container, and Fargate handles all the underlying infrastructure.

Fargate represents a fundamental shift in how we run containers in the cloud: from managing server clusters to simply specifying resources. This abstraction allows teams to focus on their applications rather than infrastructure, accelerating development and reducing operational complexity.

Fargate's architecture is built on a multi-tenant infrastructure that completely isolates tasks from each other, providing hypervisor-level security while maintaining the flexibility of Docker containers.

Pricing model and cost optimization

Pricing structure

Fargate charges per second with a 1-minute minimum billing:

On-Demand:

  • vCPU: $0.04048 per vCPU per hour
  • Memory: $0.004445 per GB per hour

Fargate Spot (up to 70% discount):

  • vCPU: $0.01215 per vCPU per hour
  • Memory: $0.001334 per GB per hour

Cost calculation example

Web application: 0.5 vCPU, 1GB RAM, running 24/7

ModeMonthly costSavings
On-Demand$17.50-
Spot$5.2570%

Batch job: 2 vCPU, 4GB RAM, 100 hours/month

ModeMonthly costSavings
On-Demand$25.89-
Spot$7.7770%

When to use Spot

  • Batch processing and analytics jobs
  • Stateless applications with interruption tolerance
  • Development and testing workloads
  • Non-critical data processing

Task sizing guide

Valid CPU/Memory combinations

vCPUAvailable memory
0.250.5GB, 1GB, 2GB
0.51GB - 4GB (1GB increments)
12GB - 8GB (1GB increments)
24GB - 16GB (1GB increments)
48GB - 30GB (1GB increments)
816GB - 60GB (4GB increments)
1632GB - 120GB (8GB increments)

Right-sizing strategies

For web applications:

  • Start with 0.5 vCPU, 1GB RAM
  • Monitor CPU and memory for 1-2 weeks
  • Scale vertically if CPU >70% or memory >80%

For batch jobs:

  • Profile locally with representative data
  • Use CloudWatch metrics to optimize
  • Consider parallelization vs resources per task

For microservices:

  • Size per service, not uniformly
  • High-frequency services: more CPU
  • Services with cache/state: more memory

Networking and security

awsvpc network mode

Fargate only supports awsvpc mode, where each task receives:

  • Its own Elastic Network Interface (ENI)
  • Unique private IP address
  • Dedicated security groups per task

ENI limits per AZ

  • Subnet /24: ~250 concurrent tasks
  • Subnet /23: ~500 concurrent tasks
  • Subnet /22: ~1000 concurrent tasks

Security groups per task

{
  "networkConfiguration": {
    "awsvpcConfiguration": {
      "subnets": ["subnet-12345", "subnet-67890"],
      "securityGroups": ["sg-web-tier", "sg-app-specific"],
      "assignPublicIp": "DISABLED"
    }
  }
}

Each task can have multiple security groups, enabling:

  • Shared base rules (sg-web-tier)
  • Application-specific rules (sg-app-specific)
  • Granular microsegmentation

Storage and persistence

Ephemeral storage

  • Default: 20GB
  • Maximum: 200GB (no additional cost)
  • Location: /tmp and container layers
  • Persistence: Only during task lifetime

EFS integration

For persistent storage:

{
  "volumes": [
    {
      "name": "efs-volume",
      "efsVolumeConfiguration": {
        "fileSystemId": "fs-12345678",
        "transitEncryption": "ENABLED",
        "authorizationConfig": {
          "accessPointId": "fsap-12345678"
        }
      }
    }
  ],
  "containerDefinitions": [
    {
      "mountPoints": [
        {
          "sourceVolume": "efs-volume",
          "containerPath": "/data"
        }
      ]
    }
  ]
}

Platform versions and evolution

Platform Version 1.4.0 (Latest)

  • Ephemeral storage: Up to 200GB
  • Logging: Fluent Bit support
  • Task metadata endpoint: v4
  • Network performance: Up to 25 Gbps

Platform Version 1.3.0

  • EFS support: Persistent volumes
  • Container insights: Enhanced metrics
  • Task metadata endpoint: v3

Platform Version 1.2.0

  • GPU support: For ML/AI workloads
  • Enhanced networking: Improved network performance

Fargate vs EC2: extended comparative analysis

DimensionFargateEC2 Launch Type
Operational overheadZero — AWS manages everythingHigh — patching, scaling, monitoring
Scaling speedSeconds (cold start ~30s)Minutes (instance launch)
Cost break-evenUnder 50% utilizationOver 50% constant utilization
Resource granularityPer individual taskPer complete instance
Security isolationHypervisor-levelShared kernel
Configuration flexibilityLimited to Fargate optionsFull host control
Time to productionDaysWeeks

When to choose each option

Fargate is ideal for:

  • Teams under 10 engineers without infrastructure expertise
  • Applications with unpredictable traffic patterns
  • Microservices with different resource requirements
  • Rapid prototyping and MVPs

EC2 is better for:

  • Applications with >70% constant utilization
  • Workloads requiring host access
  • Extreme cost optimization at scale
  • Complex network configurations

Terraform example with Spot

# Capacity provider with Fargate Spot
resource "aws_ecs_capacity_provider" "fargate_spot" {
  name = "FARGATE_SPOT"
}
 
resource "aws_ecs_cluster_capacity_providers" "main" {
  cluster_name = aws_ecs_cluster.main.name
  
  capacity_providers = ["FARGATE", "FARGATE_SPOT"]
  
  default_capacity_provider_strategy {
    capacity_provider = "FARGATE_SPOT"
    weight           = 4
    base            = 0
  }
  
  default_capacity_provider_strategy {
    capacity_provider = "FARGATE"
    weight           = 1
    base            = 1
  }
}
 
# Task definition optimized for Spot
resource "aws_ecs_task_definition" "batch_job" {
  family                   = "batch-processor"
  network_mode            = "awsvpc"
  requires_compatibilities = ["FARGATE"]
  cpu                     = 1024
  memory                  = 2048
  execution_role_arn      = aws_iam_role.execution.arn
  task_role_arn          = aws_iam_role.task.arn
  
  ephemeral_storage {
    size_in_gib = 50
  }
  
  container_definitions = jsonencode([
    {
      name  = "processor"
      image = "my-batch-processor:latest"
      
      logConfiguration = {
        logDriver = "awslogs"
        options = {
          "awslogs-group"         = "/ecs/batch-processor"
          "awslogs-region"        = "us-east-1"
          "awslogs-stream-prefix" = "ecs"
        }
      }
      
      environment = [
        {
          name  = "SPOT_INSTANCE"
          value = "true"
        }
      ]
    }
  ])
}

Monitoring and observability

Key CloudWatch metrics

  • CPUUtilization: >80% indicates need for more vCPU
  • MemoryUtilization: >85% indicates need for more memory
  • TaskCount: For monitoring auto-scaling
  • RunningTaskCount: Active vs desired tasks

Container Insights

Enables detailed metrics automatically:

{
  "containerDefinitions": [
    {
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/aws/ecs/containerinsights/cluster-name/performance"
        }
      }
    }
  ]
}

Why it matters

Fargate represents the natural evolution of container computing toward a fully serverless model. For most teams, it eliminates weeks of infrastructure setup and maintenance work, allowing focus on code that generates business value. Its per-second pricing model and Spot capacity make it economically viable for a wide range of workloads. However, for applications with high constant utilization (>70%), EC2 may still be more economical. The choice between Fargate and EC2 isn't technical but strategic: do you prefer to optimize for development speed or operational cost?

References

  • AWS Fargate User Guide — AWS, 2024. Complete official documentation.
  • Fargate Task Definitions — AWS, 2024. Detailed task configuration.
  • Fargate Pricing — AWS, 2024. Pricing calculator and examples.
  • Fargate Platform Versions — AWS, 2024. Features by platform version.
  • Fargate Spot Documentation — AWS, 2024. Capacity provider configuration.
  • ECS Networking with Fargate — AWS, 2024. Network and security group configuration.

Related content

  • AWS ECS

    AWS container orchestration service that runs and scales Docker applications without managing the underlying cluster infrastructure.

  • Serverless

    Cloud computing model where the provider manages infrastructure automatically, allowing code execution without provisioning or managing servers, paying only for actual usage.

  • Docker

    Container platform that packages applications with all dependencies into portable, consistent units that run identically in any environment.

  • Terraform AWS Serverless Modules

    Collection of 13 Terraform modules published on the Terraform Registry for deploying serverless architectures on AWS, with 12 examples covering basic ECS to full-stack CRUD with DynamoDB and AgentCore with MCP.

Concepts