Alarm

class aws_cdk.aws_cloudwatch.Alarm(scope, id, *, metric, evaluation_periods, threshold, actions_enabled=None, alarm_description=None, alarm_name=None, comparison_operator=None, datapoints_to_alarm=None, evaluate_low_sample_count_percentile=None, period=None, statistic=None, treat_missing_data=None)

Bases: aws_cdk.core.Resource

An alarm on a CloudWatch metric.

__init__(scope, id, *, metric, evaluation_periods, threshold, actions_enabled=None, alarm_description=None, alarm_name=None, comparison_operator=None, datapoints_to_alarm=None, evaluate_low_sample_count_percentile=None, period=None, statistic=None, treat_missing_data=None)
Parameters
  • scope (Construct) –

  • id (str) –

  • props

  • metric (IMetric) – The metric to add the alarm on. Metric objects can be obtained from most resources, or you can construct custom Metric objects by instantiating one.

  • evaluation_periods (Union[int, float]) – The number of periods over which data is compared to the specified threshold.

  • threshold (Union[int, float]) – The value against which the specified statistic is compared.

  • actions_enabled (Optional[bool]) – Whether the actions for this alarm are enabled. Default: true

  • alarm_description (Optional[str]) – Description for the alarm. Default: No description

  • alarm_name (Optional[str]) – Name of the alarm. Default: Automatically generated name

  • comparison_operator (Optional[ComparisonOperator]) – Comparison to use to check if metric is breaching. Default: GreaterThanOrEqualToThreshold

  • datapoints_to_alarm (Union[int, float, None]) – The number of datapoints that must be breaching to trigger the alarm. This is used only if you are setting an “M out of N” alarm. In that case, this value is the M. For more information, see Evaluating an Alarm in the Amazon CloudWatch User Guide. Default: evaluationPeriods

  • evaluate_low_sample_count_percentile (Optional[str]) – Specifies whether to evaluate the data and potentially change the alarm state if there are too few data points to be statistically significant. Used only for alarms that are based on percentiles. Default: - Not configured.

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • statistic (Optional[str]) – What function to use for aggregating. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” Default: Average

  • treat_missing_data (Optional[TreatMissingData]) – Sets how this alarm is to handle missing data points. Default: TreatMissingData.Missing

Return type

None

Methods

add_alarm_action(*actions)

Trigger this action if the alarm fires.

Typically the ARN of an SNS topic or ARN of an AutoScaling policy.

Parameters

actions (IAlarmAction) –

Return type

None

add_insufficient_data_action(*actions)

Trigger this action if there is insufficient data to evaluate the alarm.

Typically the ARN of an SNS topic or ARN of an AutoScaling policy.

Parameters

actions (IAlarmAction) –

Return type

None

add_ok_action(*actions)

Trigger this action if the alarm returns from breaching state into ok state.

Typically the ARN of an SNS topic or ARN of an AutoScaling policy.

Parameters

actions (IAlarmAction) –

Return type

None

to_annotation()

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.

Return type

HorizontalAnnotation

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

alarm_arn

ARN of this alarm.

attribute: :attribute:: true

Return type

str

alarm_name

Name of this alarm.

attribute: :attribute:: true

Return type

str

metric

The metric object this alarm was based on.

Return type

IMetric

node

Construct tree node which offers APIs for interacting with the construct tree.

Return type

ConstructNode

stack

The stack in which this resource is defined.

Return type

Stack

Static Methods

classmethod from_alarm_arn(scope, id, alarm_arn)
Parameters
  • scope (Construct) –

  • id (str) –

  • alarm_arn (str) –

Return type

IAlarm

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters

x (Any) –

Return type

bool