# AlarmBehavior

Deployment behavior when an ECS Service Deployment Alarm is triggered.

- Source: [`aws-ecs/lib/base/base-service.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts#L166)
- Type last changed: v2.87.0 · 6 Jul 2023

## Example

```ts
import * as cw from 'aws-cdk-lib/aws-cloudwatch';

declare const cluster: ecs.Cluster;
declare const taskDefinition: ecs.TaskDefinition;
declare const elbAlarm: cw.Alarm;

const service = new ecs.FargateService(this, 'Service', {
  cluster,
  taskDefinition,
  minHealthyPercent: 100,
  deploymentAlarms: {
    alarmNames: [elbAlarm.alarmName],
    behavior: ecs.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], {
  behavior: ecs.AlarmBehavior.FAIL_ON_ALARM,
});
```

## Members

| Member | Description |
| --- | --- |
| `ROLLBACK_ON_ALARM` | ROLLBACK_ON_ALARM causes the service to roll back to the previous deployment when any deployment alarm enters the 'Alarm' state. |
| `FAIL_ON_ALARM` | FAIL_ON_ALARM causes the deployment to fail immediately when any deployment alarm enters the 'Alarm' state. |

## Referenced by

- [`DeploymentAlarmOptions`](/v2/docs/aws-cdk-lib.aws_ecs.DeploymentAlarmOptions).behavior
