Use existing ebs volume (or a snapshot of existing ebs volume) with ECS?

2

Can someone please help me with the task definition for using the existing EBS volume with ECS

AWS documentation says

You can attach at most one Amazon EBS volume to each Amazon ECS task, and it must be a new volume. You can't attach an existing Amazon EBS volume to a task. However, you can configure a new Amazon EBS volume at deployment using the snapshot of an existing volume

I wish to achieve the above i.e. create a ECS task with existing EBS volume as a data volume and my scanner image will scan the data volume

I wrote the following task definition but I am confused how to use the mountOptions to use an existing snapshot

{
  "containerDefinitions": [
    {
      "name": "scanner",
      "image": "account-id.dkr.ecr.ap-south-1.amazonaws.com/scanner",
      "repositoryCredentials": {
        "credentialsParameter": "arn:aws:secretsmanager:ap-southeast-1:account-id:secret:reg-credentials"
    },
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/my-application",
          "awslogs-region": "region",
          "awslogs-stream-prefix": "ecs"
        }
      }
    }
  ],
  "requiresCompatibilities": ["EC2"],
  "cpu": "256",
  "memory": "512",
  "executionRoleArn": "arn:aws:iam::account-id:role/ecsTaskExecutionRole",
  "taskRoleArn": "arn:aws:iam::account-id:role/ecsTaskRole"
}
1 Answer
1

Hello,

To allow Amazon ECS to create a new volume from a snapshot and attach to a each new task during create, update service. You can define the snapshotId in the AWS::ECS::Service ServiceManagedEBSVolumeConfiguration.

Here is the documentation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-service-servicemanagedebsvolumeconfiguration.html

profile picture
EXPERT
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions