diff --git a/packages/@aws-cdk/aws-ecs/lib/external/external-task-definition.ts b/packages/@aws-cdk/aws-ecs/lib/external/external-task-definition.ts index de9fa8b87e9dc..74be4e73ac2d4 100644 --- a/packages/@aws-cdk/aws-ecs/lib/external/external-task-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/external/external-task-definition.ts @@ -8,7 +8,6 @@ import { ITaskDefinition, NetworkMode, TaskDefinition, - Volume, } from '../base/task-definition'; /** @@ -75,13 +74,6 @@ export class ExternalTaskDefinition extends TaskDefinition implements IExternalT }); } - /** - * Overridden method to throw error, as volumes are not supported for external task definitions - */ - public addVolume(_volume: Volume) { - throw new Error('External task definitions doesnt support volumes'); - } - /** * Overriden method to throw error as interface accelerators are not supported for external tasks */ diff --git a/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts b/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts index bcb65634c353d..19224cd873573 100644 --- a/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts @@ -601,17 +601,30 @@ describe('external task definition', () => { Annotations.fromStack(stack).hasWarning('/Default/ExternalTaskDef/web', "Proper policies need to be attached before pulling from ECR repository, or use 'fromEcrRepository'."); }); - test('correctly sets volumes from', () => { + test('correctly sets volumes', () => { + // GIVEN const stack = new cdk.Stack(); const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef', {}); - // THEN - expect(() => taskDefinition.addVolume({ + // WHEN + taskDefinition.addVolume({ host: { sourcePath: '/tmp/cache', }, name: 'scratch', - })).toThrow('External task definitions doesnt support volumes' ); + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + Volumes: [ + { + Host: { + SourcePath: '/tmp/cache', + }, + Name: 'scratch', + }, + ], + }); }); test('error when interferenceAccelerators set', () => {