java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
All Implemented Interfaces:
IResource, IAlarm, IAlarmRule, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.95.0 (build f1ff514)", date="2024-03-26T18:09:20.777Z") @Stability(Stable) public class Alarm extends AlarmBase
An alarm on a CloudWatch metric.

Example:

 import software.amazon.awscdk.services.cloudwatch.*;
 Alias alias;
 // or add alarms to an existing group
 Alias blueGreenAlias;
 Alarm alarm = Alarm.Builder.create(this, "Errors")
         .comparisonOperator(ComparisonOperator.GREATER_THAN_THRESHOLD)
         .threshold(1)
         .evaluationPeriods(1)
         .metric(alias.metricErrors())
         .build();
 LambdaDeploymentGroup deploymentGroup = LambdaDeploymentGroup.Builder.create(this, "BlueGreenDeployment")
         .alias(alias)
         .deploymentConfig(LambdaDeploymentConfig.LINEAR_10PERCENT_EVERY_1MINUTE)
         .alarms(List.of(alarm))
         .build();
 deploymentGroup.addAlarm(Alarm.Builder.create(this, "BlueGreenErrors")
         .comparisonOperator(ComparisonOperator.GREATER_THAN_THRESHOLD)
         .threshold(1)
         .evaluationPeriods(1)
         .metric(blueGreenAlias.metricErrors())
         .build());
 
  • Constructor Details

    • Alarm

      protected Alarm(software.amazon.jsii.JsiiObjectRef objRef)
    • Alarm

      protected Alarm(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Alarm

      @Stability(Stable) public Alarm(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull AlarmProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • fromAlarmArn

      @Stability(Stable) @NotNull public static IAlarm fromAlarmArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String alarmArn)
      Import an existing CloudWatch alarm provided an ARN.

      Parameters:
      scope - The parent creating construct (usually this). This parameter is required.
      id - The construct's name. This parameter is required.
      alarmArn - Alarm ARN (i.e. arn:aws:cloudwatch::invalid input: '<'account-id>:alarm:Foo). This parameter is required.
    • fromAlarmName

      @Stability(Stable) @NotNull public static IAlarm fromAlarmName(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String alarmName)
      Import an existing CloudWatch alarm provided an Name.

      Parameters:
      scope - The parent creating construct (usually this). This parameter is required.
      id - The construct's name. This parameter is required.
      alarmName - Alarm Name. This parameter is required.
    • addAlarmAction

      @Stability(Stable) public void addAlarmAction(@NotNull @NotNull IAlarmAction... actions)
      Trigger this action if the alarm fires.

      Typically SnsAcion or AutoScalingAction.

      Overrides:
      addAlarmAction in class AlarmBase
      Parameters:
      actions - This parameter is required.
    • toAnnotation

      @Stability(Stable) @NotNull public HorizontalAnnotation toAnnotation()
      Turn this alarm into a horizontal annotation.

      This is useful if you want to represent an Alarm in a non-AlarmWidget. An AlarmWidget can directly show an alarm, but it can only show a single alarm and no other metrics. Instead, you can convert the alarm to a HorizontalAnnotation and add it as an annotation to another graph.

      This might be useful if:

      • You want to show multiple alarms inside a single graph, for example if you have both a "small margin/long period" alarm as well as a "large margin/short period" alarm.
      • You want to show an Alarm line in a graph with multiple metrics in it.
    • getAlarmArn

      @Stability(Stable) @NotNull public String getAlarmArn()
      ARN of this alarm.
      Specified by:
      getAlarmArn in interface IAlarm
      Specified by:
      getAlarmArn in class AlarmBase
    • getAlarmName

      @Stability(Stable) @NotNull public String getAlarmName()
      Name of this alarm.
      Specified by:
      getAlarmName in interface IAlarm
      Specified by:
      getAlarmName in class AlarmBase
    • getMetric

      @Stability(Stable) @NotNull public IMetric getMetric()
      The metric object this alarm was based on.