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

feat(aws-ecs): add support for ECS Exec #14669

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ export interface BaseServiceOptions {
*
*/
readonly capacityProviderStrategies?: CapacityProviderStrategy[];

/**
* Whether to enable Amazon ECS Exec for this service.
*
* @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html
* @default false
*/
readonly enableExecuteCommand?: boolean;
}

/**
Expand Down Expand Up @@ -396,6 +404,7 @@ export abstract class BaseService extends Resource
/* role: never specified, supplanted by Service Linked Role */
networkConfiguration: Lazy.any({ produce: () => this.networkConfiguration }, { omitEmptyArray: true }),
serviceRegistries: Lazy.any({ produce: () => this.serviceRegistries }, { omitEmptyArray: true }),
enableExecuteCommand: props.enableExecuteCommand,
...additionalProps,
});

Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-ecs/test/ec2/ec2-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ nodeunitShim({
}),
serviceName: 'bonjour',
vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC },
enableExecuteCommand: true,
});

service.addPlacementConstraints(PlacementConstraint.memberOf('attribute:ecs.instance-type =~ t2.*'));
Expand All @@ -186,6 +187,7 @@ nodeunitShim({
Type: ecs.DeploymentControllerType.CODE_DEPLOY,
},
DesiredCount: 2,
EnableExecuteCommand: true,
LaunchType: LaunchType.EC2,
NetworkConfiguration: {
AwsvpcConfiguration: {
Expand Down
25 changes: 25 additions & 0 deletions packages/@aws-cdk/aws-ecs/test/fargate/fargate-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,31 @@ nodeunitShim({
test.done();
},

'with ECS Exec enabled'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const cluster = new ecs.Cluster(stack, 'EcsCluster');
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef');

taskDefinition.addContainer('Container', {
image: ecs.ContainerImage.fromRegistry('hello'),
});

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

// THEN
expect(stack).to(haveResource('AWS::ECS::Service', {
EnableExecuteCommand: true,
}));

test.done();
},

'throws an exception if both serviceArn and serviceName were provided for fromEc2ServiceAttributes'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down