I want to increase disk space for my Amazon Elastic Container Service (Amazon ECS) container on AWS Fargate.
Short description
By default, Fargate tasks that are launched with platform version 1.40 include a task storage size of 20 GiB as a single ephemeral volume. If you need more than 20 GiB of storage, then use one of the following options to configure more storage:
Important: When you create an Amazon EFS volume, use the same Amazon Virtual Private Cloud (Amazon VPC) and subnets that are assigned to your Fargate service.
Resolution
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.
To increase disk space for an Amazon ECS container on Fargate, complete the tasks based on your use case.
Configure ephemeral storage
Complete the following steps:
-
Create or update the task definition to configure the ephemeral storage for the task. For example:
"containerDefinitions": [ {
"memory": 128,
"essential": true,
"name": "nginx",
"image": "nginx"
}
]
"ephemeralStorage": {
"sizeInGiB": 30
}
-
Use the updated task definition to run the task.
Note: For tasks that are associated with a service, select a new task definition revision to update the service.
For more information, see Use bind mounts with Amazon ECS.
Configure storage with Amazon EFS volumes
Complete the following steps:
- Create a security group for your Amazon EFS mount targets. Then, add an inbound rule to accept NFS traffic on port 2049 from the source's task security group.
- Create an Amazon EFS file system, and then attach the security group to your mount targets.
Note: By default, a mount target is configured in each Availability Zone in a given AWS Region. Select all the Availability Zones where the VPC subnets for the Fargate service are located.
- Note the file system ID of your file system. For example: fs-12345678
- Create or update a task definition to configure a volume for the Amazon ECS task that has your Amazon EFS file system. For example:
"volumes": [ {
"name": "efs-test-volume",
"efsVolumeConfiguration": {
"fileSystemId": "fs-12345678",
"transitEncryption": "ENABLED"
}
}
]
Note: Replace fs-12345678 with your file system ID.
- Use a container definitions section to create a mount point for the volume inside your container. For example:
"containerDefinitions": [ {
"memory": 128,
"portMappings": [
{
"hostPort": 80,
"containerPort": 80,
"protocol": "tcp"
}
],
"essential": true,
"mountPoints": [
{
"containerPath": "/mount/path/inside/container",
"sourceVolume": "efs-test-volume"
}
],
"name": "nginx",
"image": "nginx"
}
]
Note: The containerPath is the path inside the container where you mount the volume. The sourceVolume is the name of your volume.
- Use your updated task definition to run the task.
Note: For tasks that are associated with a service, select a new task definition revision to update the service.
Attach an EBS volume to Fargate
Complete the following steps:
-
Create or update the task definition to configure the EBS volume to be configured at launch. Use the "configuredAtLaunch" option set to true. For example:
"containerDefinitions": [
{
"name": "nginx",
"image": "public.ecr.aws/nginx/nginx:latest",
"networkMode": "awsvpc",
"portMappings": [
{
"name": "nginx-80-tcp",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"mountPoints": [
{
"sourceVolume": "myEBSVolume",
"containerPath": "/mount/ebs",
"readOnly": true
}
]
}
],
"volumes": [
{
"name": "myEBSVolume",
"configuredAtLaunch": true
}
]
-
Launch a standalone task. Or, launch a task as part of a service with a volume configuration as part of the JSON.
Standalone tasks JSON example:
{
"cluster": "mycluster",
"taskDefinition": "mytaskdef",
"volumeConfigurations": [
{
"name": "datadir",
"managedEBSVolume": {
"volumeType": "gp3",
"sizeInGiB": 100,
"roleArn": "arn:aws:iam:1111222333:role/ecsInfrastructureRole",
"encrypted": true,
"kmsKeyId": "arn:aws:kms:region:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
}
}
]
}
Note: As seen in the preceding example, a snapshot isn't needed to launch the task.
Service JSON example:
{
"cluster": "mycluster",
"taskDefinition": "mytaskdef",
"serviceName": "mysvc",
"desiredCount": 2,
"volumeConfigurations": [
{
"name": "myEbsVolume",
"managedEBSVolume": {
"roleArn":"arn:aws:iam:1111222333:role/ecsInfrastructureRole",
"snapshotId": "snap-12345"
}
}
]
}
Note: Replace roleArn with your account ecsInfrastructureRole. Replace snapshotId with the snapshot ID that you want to create a volume from.