Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ecs): ecs exec cannot be enabled for ECS Anywhere (ecs.ExternalService) #31374

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/aws-cdk-lib/aws-ecs/lib/external/external-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ export class ExternalService extends BaseService implements IExternalService {
throw new Error ('Cloud map options are not supported for External service');
}

if (props.enableExecuteCommand !== undefined) {
throw new Error ('Enable Execute Command options are not supported for External service');
}

if (props.capacityProviderStrategies !== undefined) {
throw new Error ('Capacity Providers are not supported for External service');
}
Expand Down
57 changes: 33 additions & 24 deletions packages/aws-cdk-lib/aws-ecs/test/external/external-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,39 @@ describe('external service', () => {
});
});

test('with enableExecuteCommand set to true', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'MyVpc', {});
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
addDefaultCapacityProvider(cluster, stack, vpc);
const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'TaskDef');

taskDefinition.addContainer('web', {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
memoryLimitMiB: 512,
});

// WHEN
new ecs.ExternalService(stack, 'ExternalService', {
cluster,
taskDefinition,
enableExecuteCommand: true,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
TaskDefinition: {
Ref: 'TaskDef54694570',
},
Cluster: {
Ref: 'EcsCluster97242B84',
},
LaunchType: LaunchType.EXTERNAL,
EnableExecuteCommand: true,
});
});

test('throws when task definition is not External compatible', () => {
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'MyVpc', {});
Expand Down Expand Up @@ -306,30 +339,6 @@ describe('external service', () => {

});

test('error if enableExecuteCommand options provided with external service', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'MyVpc', {});
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
addDefaultCapacityProvider(cluster, stack, vpc);
const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'TaskDef');

taskDefinition.addContainer('web', {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
memoryLimitMiB: 512,
});

// THEN
expect(() => new ecs.ExternalService(stack, 'ExternalService', {
cluster,
taskDefinition,
enableExecuteCommand: true,
})).toThrow('Enable Execute Command options are not supported for External service');

// THEN

});

test('error if capacityProviderStrategies options provided with external service', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
Loading