A Fargate Task Definition
Fargate task definitions require awsvpc networking and specific CPU/memory values.
Fargate task definitions have a few rules that differ from EC2:
requiresCompatibilitiesmust includeFARGATE.networkModemust beawsvpc.- Task-level
cpuandmemoryare required and must be a valid pair. - An
executionRoleArnis needed to pull private images and write logs.
Example
{
"family": "api",
"requiresCompatibilities": [
"FARGATE"
],
"networkMode": "awsvpc",
"cpu": "512",
"memory": "1024",
"executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
"containerDefinitions": [
{
"name": "api",
"image": "123456789012.dkr.ecr.us-east-1.amazonaws.com/api:7",
"essential": true,
"portMappings": [
{
"containerPort": 8080
}
]
}
]
}When to use it
- A developer writes a Fargate task definition specifying awsvpc networking and exact CPU/memory values so ECS can validate it at registration time.
- A team sets the Fargate platform version in their task definition to lock the underlying kernel version for a compliance audit.
- An ops engineer adds an ephemeralStorage field to a Fargate task definition to give a data-processing container 50 GB of scratch space.
More examples
Minimal Fargate Task Definition
A complete Fargate task definition requiring awsvpc network mode, valid CPU/memory combination, and an execution role ARN.
{
"family": "fargate-api",
"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/api:v3",
"portMappings": [{"containerPort": 8080}],
"essential": true
}
]
}Add Expanded Ephemeral Storage
Adds 50 GiB of ephemeral scratch storage to a Fargate task, beyond the default 20 GiB, for large data-processing workloads.
{
"family": "data-processor",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "1024",
"memory": "4096",
"ephemeralStorage": {"sizeInGiB": 50},
"containerDefinitions": [
{"name": "processor", "image": "my-proc:latest", "essential": true}
]
}Register Fargate Task Def from File
Registers the Fargate task definition JSON and prints the resulting family, revision number, and status to confirm success.
aws ecs register-task-definition \
--cli-input-json file://fargate-task-def.json \
--query 'taskDefinition.{family:family,revision:revision,status:status}'
Discussion