DeploymentAlarmOptions Struct
Options for deployment alarms.
| Source | aws-ecs/lib/base/base-service.ts |
|---|---|
| Type last changed |
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,
});
python
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,
min_healthy_percent=100,
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
)
java
import software.amazon.awscdk.services.cloudwatch.*;
Cluster cluster;
TaskDefinition taskDefinition;
Alarm elbAlarm;
FargateService service = FargateService.Builder.create(this, "Service")
.cluster(cluster)
.taskDefinition(taskDefinition)
.minHealthyPercent(100)
.deploymentAlarms(DeploymentAlarmConfig.builder()
.alarmNames(List.of(elbAlarm.getAlarmName()))
.behavior(AlarmBehavior.ROLLBACK_ON_ALARM)
.build())
.build();
// Defining a deployment alarm after the service has been created
String cpuAlarmName = "MyCpuMetricAlarm";
Alarm.Builder.create(this, "CPUAlarm")
.alarmName(cpuAlarmName)
.metric(service.metricCpuUtilization())
.evaluationPeriods(2)
.threshold(80)
.build();
service.enableDeploymentAlarms(List.of(cpuAlarmName), DeploymentAlarmOptions.builder()
.behavior(AlarmBehavior.FAIL_ON_ALARM)
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.CloudWatch;
Cluster cluster;
TaskDefinition taskDefinition;
Alarm elbAlarm;
var service = new FargateService(this, "Service", new FargateServiceProps {
Cluster = cluster,
TaskDefinition = taskDefinition,
MinHealthyPercent = 100,
DeploymentAlarms = new DeploymentAlarmConfig {
AlarmNames = new [] { elbAlarm.AlarmName },
Behavior = AlarmBehavior.ROLLBACK_ON_ALARM
}
});
// Defining a deployment alarm after the service has been created
var cpuAlarmName = "MyCpuMetricAlarm";
new Alarm(this, "CPUAlarm", new AlarmProps {
AlarmName = cpuAlarmName,
Metric = service.MetricCpuUtilization(),
EvaluationPeriods = 2,
Threshold = 80
});
service.EnableDeploymentAlarms(new [] { cpuAlarmName }, new DeploymentAlarmOptions {
Behavior = AlarmBehavior.FAIL_ON_ALARM
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import cw "github.com/aws/aws-cdk-go/awscdk"
var cluster Cluster
var taskDefinition TaskDefinition
var elbAlarm Alarm
service := ecs.NewFargateService(this, jsii.String("Service"), &FargateServiceProps{
Cluster: Cluster,
TaskDefinition: TaskDefinition,
MinHealthyPercent: jsii.Number(100),
DeploymentAlarms: &DeploymentAlarmConfig{
AlarmNames: []*string{
elbAlarm.alarmName,
},
Behavior: ecs.AlarmBehavior_ROLLBACK_ON_ALARM,
},
})
// Defining a deployment alarm after the service has been created
cpuAlarmName := "MyCpuMetricAlarm"
cw.NewAlarm(this, jsii.String("CPUAlarm"), &AlarmProps{
AlarmName: cpuAlarmName,
Metric: service.MetricCpuUtilization(),
EvaluationPeriods: jsii.Number(2),
Threshold: jsii.Number(80),
})
service.EnableDeploymentAlarms([]*string{
cpuAlarmName,
}, &DeploymentAlarmOptions{
Behavior: ecs.AlarmBehavior_FAIL_ON_ALARM,
})
Properties
behavioroptionalAlarmBehaviorbehavioroptionalAlarmBehaviorbehavioroptionalAlarmBehaviorBehavioroptionalAlarmBehaviorBehavioroptionalAlarmBehavior = AlarmBehavior.ROLLBACK_ON_ALARM #Default rollback on alarm.