Skip to content

Commit

Permalink
Add code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhcsun committed Jan 5, 2024
1 parent d493c61 commit ec4fc59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class Ec2Service extends BaseService implements IEc2Service {
{
cluster: props.cluster.clusterName,
taskDefinition: props.deploymentController?.type === DeploymentControllerType.EXTERNAL ? undefined : props.taskDefinition.taskDefinitionArn,
placementConstraints: Lazy.any({ produce: () => this.constraints }, { omitEmptyArray: true }),
placementConstraints: Lazy.any({ produce: () => this.constraints }),
placementStrategies: Lazy.any({ produce: () => this.strategies }, { omitEmptyArray: true }),
schedulingStrategy: props.daemon ? 'DAEMON' : 'REPLICA',
}, props.taskDefinition);
Expand Down
28 changes: 27 additions & 1 deletion packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1849,10 +1849,36 @@ describe('ec2 service', () => {

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
PlacementConstraints: Match.absent(),
PlacementConstraints: Match.arrayEquals([]),
});
});

test('with an empty list in placement constraints', () => {
// 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.Ec2TaskDefinition(stack, 'Ec2TaskDef');

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

new ecs.Ec2Service(stack, 'Ec2Service', {
cluster,
taskDefinition,
placementConstraints: [],
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
PlacementConstraints: Match.arrayEquals([]),
});

});

testDeprecated('with both propagateTags and propagateTaskTagsFrom defined', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit ec4fc59

Please sign in to comment.