aws-cdk-lib.aws_ecs.AlarmBehavior

enum AlarmBehavior

LanguageType name
.NETAmazon.CDK.AWS.ECS.AlarmBehavior
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsecs#AlarmBehavior
Javasoftware.amazon.awscdk.services.ecs.AlarmBehavior
Pythonaws_cdk.aws_ecs.AlarmBehavior
TypeScript (source)aws-cdk-lib » aws_ecs » AlarmBehavior

Deployment behavior when an ECS Service Deployment Alarm is triggered.

Example

import * as cw from 'aws-cdk-lib/aws-cloudwatch';
declare const cluster: ecs.Cluster;
declare const taskDefinition: ecs.TaskDefinition;
declare const elbAlarm: cloudwatch.Alarm;
const service = new ecs.FargateService(this, 'Service', {
  cluster,
  taskDefinition,
  deploymentAlarms: {
    alarms: [elbAlarm.alarmName]
    behavior: AlarmBehavior.ROLLBACK_ON_ALARM,
  },
});

// Defining a deployment alarm after the service has been created
const cpuAlarmName =  'MyCpuMetricAlarm';
new cw.Alarm(this, 'CPUAlarm', {
  alarmName: cpuAlarmName,
  metric: service.metricCpuUtilization(),
  evaluationPeriods: 2,
  threshold: 80,
});
service.enableDeploymentAlarms([cpuAlarmName], AlarmBehavior.FAIL_ON_ALARM);

Members

NameDescription
ROLLBACK_ON_ALARMROLLBACK_ON_ALARM causes the service to roll back to the previous deployment when any deployment alarm enters the 'Alarm' state.
FAIL_ON_ALARMFAIL_ON_ALARM causes the deployment to fail immediately when any deployment alarm enters the 'Alarm' state.

ROLLBACK_ON_ALARM

ROLLBACK_ON_ALARM causes the service to roll back to the previous deployment when any deployment alarm enters the 'Alarm' state.

The Cloudformation stack will be rolled back and enter state "UPDATE_ROLLBACK_COMPLETE".


FAIL_ON_ALARM

FAIL_ON_ALARM causes the deployment to fail immediately when any deployment alarm enters the 'Alarm' state.

In order to restore functionality, you must roll the stack forward by pushing a new version of the ECS service.