Skip to content

Instantly share code, notes, and snippets.

@nirsky
Created June 4, 2020 08:09
Show Gist options
  • Save nirsky/610e3888a72927afbcd61d7126635b04 to your computer and use it in GitHub Desktop.
Save nirsky/610e3888a72927afbcd61d7126635b04 to your computer and use it in GitHub Desktop.
import { Ec2TaskDefinition, Scope, ContainerDefinition } from '@aws-cdk/aws-ecs';
// Create TaskDefinition
const taskDefinition = new Ec2TaskDefinition(...);
// Add EBS volume, this will also create the volume
// Look here to understand all the options:
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-volumes.html
const VOLUME_NAME = 'my-ebs-volume';
taskDefinition.addVolume({
name: VOLUME_NAME,
dockerVolumeConfiguration: {
autoprovision: true,
scope: Scope.SHARED,
driver: 'rexray/ebs',
driverOpts: {
volumetype: 'gp2',
size: '10',
},
},
});
// Add your docker container
const myContainer: ContainerDefinition = taskDefinition.addContainer(...);
// Mount the volume to your container
myContainer.addMountPoints({
sourceVolume: VOLUME_NAME,
containerPath: '/path/to/mount',
readOnly: false,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment