Key Takeaways

  • AWS Fargate is a serverless compute engine for containers — you define CPU/memory and a container image; AWS runs it without you provisioning or managing EC2 instances.
  • Fargate works with both Amazon ECS and Amazon EKS as the launch type/compute option, not as a separate orchestrator.
  • You pay per vCPU and GB of memory, per second, for the duration the task runs — no idle EC2 capacity to pay for.
  • Fargate removes node patching, cluster capacity planning, and AMI management, at the cost of less control over the underlying host (no SSH, no DaemonSets, no privileged containers in most cases).
  • It's a strong default for stateless web services, APIs, batch jobs, and bursty workloads; EC2-backed nodes remain better for GPU workloads, high-density packing, or workloads needing host-level access.

What "Serverless Containers" Actually Means

With standard ECS or EKS on EC2, you provision worker instances, size them, patch them, and manage scaling groups — the orchestrator schedules containers onto that fleet. Fargate removes the fleet. You describe a task (container image, CPU, memory, networking), and AWS finds and manages the underlying compute transparently.

EC2-Backed You manage: EC2 fleet, AMIs, scaling Orchestrator schedules tasks onto nodes Containers run Fargate AWS manages compute (hidden) You define task: image, CPU, memory Containers run

Fargate With ECS vs. Fargate With EKS

ECS + FargateEKS + Fargate
OrchestratorAWS's native ECS schedulerStandard Kubernetes
Best forTeams that want AWS-native simplicityTeams standardized on Kubernetes tooling
Config unitTask definition (JSON)Kubernetes Pod spec + Fargate profile

Defining a Fargate Task (ECS)

// task-definition.json
{
  "family": "f9-api-service",
  "networkMode": "awsvpc",
  "requiresCompatibilities": ["FARGATE"],
  "cpu": "512",
  "memory": "1024",
  "executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
  "containerDefinitions": [
    {
      "name": "api",
      "image": "123456789012.dkr.ecr.us-east-1.amazonaws.com/f9-api:latest",
      "portMappings": [{ "containerPort": 8080, "protocol": "tcp" }],
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/f9-api-service",
          "awslogs-region": "us-east-1",
          "awslogs-stream-prefix": "api"
        }
      }
    }
  ]
}
# Register the task definition and run it on a Fargate cluster
aws ecs register-task-definition --cli-input-json file://task-definition.json

aws ecs run-task \
  --cluster f9-cluster \
  --launch-type FARGATE \
  --task-definition f9-api-service \
  --network-configuration "awsvpcConfiguration={subnets=[subnet-0abc],securityGroups=[sg-0def],assignPublicIp=ENABLED}"

Running a Fargate Service With Terraform

resource "aws_ecs_cluster" "f9_cluster" {
  name = "f9-cluster"
}

resource "aws_ecs_task_definition" "api" {
  family                   = "f9-api-service"
  requires_compatibilities = ["FARGATE"]
  network_mode             = "awsvpc"
  cpu                      = "512"
  memory                   = "1024"
  execution_role_arn       = aws_iam_role.ecs_execution.arn

  container_definitions = jsonencode([
    {
      name      = "api"
      image     = "123456789012.dkr.ecr.us-east-1.amazonaws.com/f9-api:latest"
      portMappings = [{ containerPort = 8080, protocol = "tcp" }]
    }
  ])
}

resource "aws_ecs_service" "api" {
  name            = "f9-api-service"
  cluster         = aws_ecs_cluster.f9_cluster.id
  task_definition = aws_ecs_task_definition.api.arn
  desired_count   = 2
  launch_type     = "FARGATE"

  network_configuration {
    subnets          = module.vpc.private_subnets
    security_groups  = [aws_security_group.api.id]
    assign_public_ip = false
  }
}

Fargate on EKS

# Fargate profile — tells EKS which pods run on Fargate
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: f9-prod-cluster
  region: us-east-1
fargateProfiles:
  - name: fp-default
    selectors:
      - namespace: default
eksctl create fargateprofile -f fargate-profile.yaml
kubectl get pods -o wide   # pods on Fargate show no visible node instance

Pricing Model

You're billed per second (minimum 1 minute) for the vCPU and memory requested in the task, not what's actually consumed — so rightsizing task CPU/memory matters directly for cost, unlike EC2 where unused headroom is "sunk" in an already-running instance anyway.

# Estimate: 0.5 vCPU, 1GB memory task running continuously for a month
# ≈ 730 hours × (0.5 vCPU rate + 1GB memory rate) — check current AWS pricing page for exact rates

When Fargate Isn't the Right Fit

  • GPU workloads — not supported on Fargate; use EC2-backed nodes.
  • High-density bin packing to minimize cost per workload at massive scale — EC2 reserved/spot capacity can be cheaper.
  • Workloads needing host-level access — privileged containers, custom kernel modules, DaemonSets on EKS.
  • Very long-running, steady-state workloads at scale, where Savings Plans on EC2-backed capacity may undercut Fargate's per-second pricing.

FAQ

Is Fargate a separate service from ECS and EKS? No — it's a compute/launch type option within ECS or EKS, not an independent orchestrator.

Can I SSH into a Fargate task? Not via traditional SSH; use aws ecs execute-command (ECS Exec) for interactive debugging access instead.

Is Fargate more expensive than EC2? Per-unit compute cost is typically higher than equivalent EC2 Reserved/Spot pricing, but it eliminates idle capacity and operational overhead — net cost depends on your workload's utilization pattern.

Does Fargate support Windows containers? Yes, AWS Fargate supports both Linux and Windows containers on ECS.

Decide Between Fargate and EC2 With Expert Guidance

Choosing the right compute model — and sizing it correctly — has a direct line to your AWS bill. f9infotech's cloud architecture team can help you decide where Fargate fits your workload mix and migrate existing ECS/EKS clusters accordingly.