What is Fargate?

AWS Fargate is the serverless launch type that runs tasks without any servers to manage.

AWS Fargate is a serverless compute engine for containers. With Fargate you never launch, patch, or scale EC2 instances — AWS provisions right-sized compute for each task.

What you give up and gain

  • Gain: no host management, per-task isolation, faster to start.
  • Give up: some control over the host and certain features (e.g. GPU support is limited, no privileged mode).

Fargate is the recommended default for most services and jobs.

Example

Example · bash
# Everything about the host is abstracted away
aws ecs run-task \
  --cluster prod \
  --launch-type FARGATE \
  --task-definition web:1 \
  --count 2 \
  --network-configuration 'awsvpcConfiguration={subnets=[subnet-abc]}'

When to use it

  • A startup runs all their microservices on Fargate so the engineering team never patches OS kernels or manages EC2 instance fleets.
  • A data team uses Fargate to run short-lived ETL containers that process S3 files, paying only for the seconds each task runs.
  • A compliance team chooses Fargate because each task gets an isolated kernel namespace, reducing the blast radius of a container escape.

More examples

Run a Fargate Task with No Servers

Launches an ETL task on Fargate; AWS provisions isolated compute automatically with no EC2 instances to configure.

Example · bash
aws ecs run-task \
  --cluster serverless-cluster \
  --launch-type FARGATE \
  --task-definition etl-job:1 \
  --network-configuration \
    'awsvpcConfiguration={subnets=[subnet-priv-a],securityGroups=[sg-egress-only],assignPublicIp=DISABLED}'

Enable Fargate Platform Version

Creates a Fargate service pinned to the LATEST platform version to get the newest kernel and security patches automatically.

Example · bash
aws ecs create-service \
  --cluster serverless-cluster \
  --service-name api \
  --task-definition api:3 \
  --launch-type FARGATE \
  --platform-version LATEST \
  --desired-count 2 \
  --network-configuration \
    'awsvpcConfiguration={subnets=[subnet-a,subnet-b],securityGroups=[sg-api],assignPublicIp=DISABLED}'

Use Fargate Spot to Cut Costs

Runs a batch task on Fargate Spot, which can be up to 70% cheaper than standard Fargate for interruption-tolerant workloads.

Example · bash
aws ecs run-task \
  --cluster serverless-cluster \
  --capacity-provider-strategy \
    '[{"capacityProvider":"FARGATE_SPOT","weight":1}]' \
  --task-definition batch-worker:2 \
  --network-configuration \
    'awsvpcConfiguration={subnets=[subnet-priv-a],securityGroups=[sg-workers],assignPublicIp=DISABLED}'

Discussion

  • Be the first to comment on this lesson.