How can I increase disk space for my Amazon ECS container on Fargate?
Last updated: 2022-01-29
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, you can configure more storage using two options:
- Use Fargate's ephemeral storage option for storage up to 200 GiB. Ephemeral storage is non-persistent storage.
- Use Amazon Elastic File System (Amazon EFS) volumes for scalable file storage. Amazon EFS volumes provide persistent 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
Configuring ephemeral storage
- Access the Amazon ECS console.
- Create a new or edit an existing task definition.
- Under Volumes, select Configure via JSON.
- In the task definition JSON, define an ephemeralStorage object. The sizeInGiB must be an integer between 21 and 200. For example:
"ephemeralStorage": { "sizeInGiB": integer}
Note: Replace integer with the number of GiB of storage needed. For more examples of configuring ephemeral storage, see Bind mount examples.
Configuring storage with Amazon EFS volumes
- 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 from step 1 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.
"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"
}
]
Did this article help?
Do you need billing or technical support?