Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ export abstract class BaseService extends Resource
} else {
// If deployment alarms have previously been enabled, we only need to add
// the new alarm names, since rollback behaviors can't be updated/mixed.
this.deploymentAlarms.alarmNames.concat(alarmNames);
this.deploymentAlarms.alarmNames.push(...alarmNames);
}
}

Expand Down
40 changes: 38 additions & 2 deletions packages/aws-cdk-lib/aws-ecs/test/base-service.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Template, Match } from '../../assertions';
import * as cloudwatch from '../../aws-cloudwatch';
import * as ec2 from '../../aws-ec2';
import * as elbv2 from '../../aws-elasticloadbalancingv2';
import * as iam from '../../aws-iam';
import * as kms from '../../aws-kms';
import * as lambda from '../../aws-lambda';
import * as cdk from '../../core';
import { App, Stack } from '../../core';
import * as cxapi from '../../cx-api';
Expand Down Expand Up @@ -309,6 +308,43 @@ describe('For alarm-based rollbacks', () => {
},
});
});

describe('enableDeploymentAlarms', () => {
test('enableDeploymentAlarms will concat alarms in the deployment configuration when called more than once', () => {
// GIVEN
const vpc = new ec2.Vpc(stack, 'Vpc');
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'),
});

const expectedAlarmNames = ['alarm1', 'alarm2', 'alarm3'];

// WHEN
const service = new ecs.FargateService(stack, 'FargateService', {
cluster,
taskDefinition,
minHealthyPercent: 100,
maxHealthyPercent: 200,
deploymentAlarms: { alarmNames: ['alarm1'] },
});

service.enableDeploymentAlarms(['alarm2']);
service.enableDeploymentAlarms(['alarm3']);

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
DeploymentConfiguration: {
Alarms: {
AlarmNames: expectedAlarmNames,
Enable: true,
Rollback: true,
},
},
});
});
});
});

describe('When specifying a task definition revision', () => {
Expand Down
Loading