I want to use Amazon Elastic Block Storage (Amazon EBS) volumes for my Amazon Elastic Container Service (Amazon ECS) tasks.
Resolution
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
Prerequisites:
To attach a new EBS volume to your task, specify the following configurations in your task definition under mountPoints:
- For sourceVolume, enter the name of the volume that you want to mount.
- For containerPath, enter the path in the container instance where you mount the volume.
- For readOnly, enter true or false based on whether the container has read-only access to the volume.
Then, set configuredAtLaunch to true.
Example task definition:
{
"family": "mytaskdef",
"containerDefinitions": [
{
....
#Some fields removed from example
....
"mountPoints": [
{
"sourceVolume": "myEBSVolume",
"containerPath": "/mount/ebs",
"readOnly": true
}
]
}
],
....
#Some fields removed from example
....
"volumes": [
{
"name": "myEBSVolume",
"configuredAtLaunch": true
}
]
}
Save the task definition template as a JSON file, and then run register-task-definition to register the task definition:
aws ecs register-task-definition \
--cli-input-json file://json_file_name.json \
--region Region_name
Note: Replace json_file_name.json with your JSON file and Region_name with your AWS Region.
Then, configure the Amazon EBS volume at deployment when you run a standalone task. Or, configure when you create or update a service.
To use data from an existing EBS volume, create a snapshot of the volume. Then, add the snapshot ID for SnapshotID under VolumeConfigurations in the task definition. For an example configuration, see Configure a volume at service creation.
Related information
Troubleshooting Amazon EBS volume attachments to Amazon ECS tasks
Use Amazon EBS volumes with Amazon ECS