Skip to content

Commit

Permalink
feat(aws-ecs): add enableExecuteCommand to Service
Browse files Browse the repository at this point in the history
  • Loading branch information
SoManyHs committed Mar 18, 2021
1 parent 0ea4b19 commit 64cc86a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
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 ability to exec into a container
*
* @default - undefined
*/
readonly enableExecuteCommand?: boolean;
}

/**
Expand Down Expand Up @@ -391,6 +399,7 @@ export abstract class BaseService extends Resource
type: DeploymentControllerType.ECS,
} : props.deploymentController,
launchType: launchType,
enableExecuteCommand: props.enableExecuteCommand,
capacityProviderStrategy: props.capacityProviderStrategies,
healthCheckGracePeriodSeconds: this.evaluateHealthGracePeriod(props.healthCheckGracePeriod),
/* role: never specified, supplanted by Service Linked Role */
Expand Down
41 changes: 41 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 @@ -49,6 +49,47 @@ nodeunitShim({
test.done();
},

'allows setting enable execute command'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'MyVpc', {});
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') });
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');

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

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

// THEN
expect(stack).to(haveResource('AWS::ECS::Service', {
TaskDefinition: {
Ref: 'Ec2TaskDef0226F28C',
},
Cluster: {
Ref: 'EcsCluster97242B84',
},
DeploymentConfiguration: {
MaximumPercent: 200,
MinimumHealthyPercent: 50,
},
LaunchType: LaunchType.EC2,
SchedulingStrategy: 'REPLICA',
EnableECSManagedTags: false,
EnableExecuteCommand: true,
}));

test.done();
},


'with custom cloudmap namespace'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down
57 changes: 57 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 @@ -195,6 +195,63 @@ nodeunitShim({
test.done();
},

'allows setting enable execute command'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'MyVpc', {});
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef');

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

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

// THEN
expect(stack).to(haveResource('AWS::ECS::Service', {
TaskDefinition: {
Ref: 'FargateTaskDefC6FB60B4',
},
Cluster: {
Ref: 'EcsCluster97242B84',
},
DeploymentConfiguration: {
MaximumPercent: 200,
MinimumHealthyPercent: 50,
},
LaunchType: LaunchType.FARGATE,
EnableECSManagedTags: false,
EnableExecuteCommand: true,
NetworkConfiguration: {
AwsvpcConfiguration: {
AssignPublicIp: 'DISABLED',
SecurityGroups: [
{
'Fn::GetAtt': [
'FargateServiceSecurityGroup0A0E79CB',
'GroupId',
],
},
],
Subnets: [
{
Ref: 'MyVpcPrivateSubnet1Subnet5057CF7E',
},
{
Ref: 'MyVpcPrivateSubnet2Subnet0040C983',
},
],
},
},
}));
test.done();
},

'with custom cloudmap namespace'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 64cc86a

Please sign in to comment.