AlarmBehavior

class aws_cdk.aws_ecs.AlarmBehavior(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Deployment behavior when an ECS Service Deployment Alarm is triggered.

ExampleMetadata:

infused

Example:

import aws_cdk.aws_cloudwatch as cw

# cluster: ecs.Cluster
# task_definition: ecs.TaskDefinition
# elb_alarm: cw.Alarm


service = ecs.FargateService(self, "Service",
    cluster=cluster,
    task_definition=task_definition,
    deployment_alarms=ecs.DeploymentAlarmConfig(
        alarm_names=[elb_alarm.alarm_name],
        behavior=ecs.AlarmBehavior.ROLLBACK_ON_ALARM
    )
)

# Defining a deployment alarm after the service has been created
cpu_alarm_name = "MyCpuMetricAlarm"
cw.Alarm(self, "CPUAlarm",
    alarm_name=cpu_alarm_name,
    metric=service.metric_cpu_utilization(),
    evaluation_periods=2,
    threshold=80
)
service.enable_deployment_alarms([cpu_alarm_name],
    behavior=ecs.AlarmBehavior.FAIL_ON_ALARM
)

Attributes

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.

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”.