Skip to content

AWS::CloudWatch::Alarm

The AWS::CloudWatch::Alarm type specifies an alarm and associates it with the specified metric or metric math expression.

Generated by cfn-typegen --out cfn_types AWS::CloudWatch::Alarm into cfn_types/cloudwatch.py:

# Generated by cfn-typegen from the CloudFormation registry schemas. Do not edit.
# fmt: off
# ruff: noqa
"""AWS::CloudWatch resources."""

from collections.abc import Mapping, Sequence
from typing import Any, Literal, NotRequired, Unpack
from typing_extensions import TypedDict
from cfn_typed.base import DeletionPolicy, DependsOn, ResourceAttrs, Tag, UpdateReplacePolicy, build
from cfn_typed.intrinsics import Expr


CONSTRAINTS:dict[str,Any]={
'AWS::CloudWatch::Alarm':{'WarmUpConfiguration':{'P':{'WarmUpPeriodDurationInMinutes':{'m':1,'M':2880}}},'Tags':{'I':50,'T':{'P':{'Value':{'l':1,'L':256},'Key':{'l':1,'L':128}}}},'ActionConfiguration':{'P':{'AlarmTagsPropagation':{'P':{'IncludedTagKeys':{'i':1,'I':50,'T':{'l':1,'L':128}},'ExcludedTagKeys':{'i':1,'I':50,'T':{'l':1,'L':128}}}}}}},
}


ATTRIBUTES:dict[str,Any]={"AWS::CloudWatch::Alarm":["AlarmName","Arn"]}


RULES:dict[str,Any]={"AWS::CloudWatch::Alarm":[[["EvaluationWindow"],"o",[["WallClockWindow"],["SlidingWindow"]]]]}
Nested types (14)

These are defined above the properties in the generated module.

class AlarmDimension(TypedDict, closed=True):
    'Dimension is an embedded property of the ``AWS::CloudWatch::Alarm`` type.'
    Value: Expr[str]
    'The value for the dimension, from 1–255 characters in length.'
    Name: Expr[str]
    'The name of the dimension, from 1–255 characters in length.'


class AlarmMetric(TypedDict, closed=True):
    'The ``Metric`` property type represents a specific metric.'
    MetricName: NotRequired[Expr[str]]
    'The name of the metric that you want the alarm to watch.'
    Dimensions: NotRequired[Expr[Sequence[Expr[AlarmDimension]]]]
    'The metric dimensions that you want to be used for the metric that the alarm will watch.'
    Namespace: NotRequired[Expr[str]]
    'The namespace of the metric that the alarm will watch.'


class AlarmMetricStat(TypedDict, closed=True):
    'This structure defines the metric to be returned, along with the statistics, period, and units.'
    Stat: Expr[str]
    'The statistic to return.'
    Period: Expr[int]
    'The granularity, in seconds, of the returned data points.'
    Metric: Expr[AlarmMetric]
    'The metric to return, including the metric name, namespace, and dimensions.'
    Unit: NotRequired[Expr[str]]
    'The unit to use for the returned data points.'


class AlarmMetricDataQuery(TypedDict, closed=True):
    'The ``MetricDataQuery`` property type specifies the metric data to return, and whether this call is just retrieving a batch set of data for one metric, or is...'
    AccountId: NotRequired[Expr[str]]
    'The ID of the account where the metrics are located, if this is a cross-account alarm.'
    ReturnData: NotRequired[Expr[bool]]
    'This option indicates whether to return the timestamps and raw data values of this metric.'
    Expression: NotRequired[Expr[str]]
    'The math expression to be performed on the returned data, if this object is performing a math expression.'
    Label: NotRequired[Expr[str]]
    'A human-readable label for this metric or expression.'
    MetricStat: NotRequired[Expr[AlarmMetricStat]]
    'The metric to be returned, along with statistics, period, and units.'
    Period: NotRequired[Expr[int]]
    'The granularity, in seconds, of the returned data points.'
    Id: Expr[str]
    'A short name used to tie this object to the results in the response.'


class AlarmWarmUpConfiguration(TypedDict, closed=True):
    'The configuration settings that define the warm-up behavior for an alarm.'
    WarmUpPeriodDurationInMinutes: NotRequired[Expr[int]]
    'The length of the warm-up period, in minutes.'
    OnlyStartEvaluatingAfterWarmUpPeriodEnds: NotRequired[Expr[bool]]
    'Specifies whether the alarm waits for the full warm-up period before it starts to evaluate.'


class AlarmWallClockWindow(TypedDict, closed=True):
    "An evaluation window that aligns the evaluated range to fixed clock boundaries that match the alarm's period, such as the top of the hour, midnight, or the s..."
    Timezone: NotRequired[Expr[str]]
    'The time zone to use when the alarm aligns the evaluation window to clock boundaries.'


class AlarmEvaluationWindow(TypedDict, closed=True):
    'The evaluation window that an alarm uses to select the range of metric data that it evaluates each time it runs.'
    WallClockWindow: NotRequired[Expr[AlarmWallClockWindow]]
    "A wall clock window, which aligns the evaluated range to fixed clock boundaries that match the alarm's period, such as the top of the hour, midnight, or the ..."
    SlidingWindow: NotRequired[Expr[Mapping[str, Any]]]
    'A sliding window, which advances each time the alarm is evaluated, forming a rolling time window.'


class AlarmAlarmPromQLCriteria(TypedDict, closed=True):
    'Contains the configuration that determines how a PromQL alarm evaluates its contributors, including the query to run and the durations that define when contr...'
    PendingPeriod: NotRequired[Expr[int]]
    'The duration, in seconds, that a contributor must be continuously breaching before it transitions to the ``ALARM`` state.'
    Query: NotRequired[Expr[str]]
    'The PromQL query that the alarm evaluates.'
    RecoveryPeriod: NotRequired[Expr[int]]
    'The duration, in seconds, that a contributor must continuously not be breaching before it transitions back to the ``OK`` state.'


class AlarmEvaluationCriteria(TypedDict, closed=True):
    'The evaluation criteria for an alarm.'
    PromQLCriteria: NotRequired[Expr[AlarmAlarmPromQLCriteria]]
    'The PromQL criteria for the alarm evaluation.'


class AlarmAlarmTagsPropagation(TypedDict, closed=True):
    IncludedTagKeys: NotRequired[Expr[list[Expr[str]]]]
    'The only tag keys to include.'
    ExcludedTagKeys: NotRequired[Expr[list[Expr[str]]]]
    'The tag keys to leave out.'
    Enabled: Expr[bool]
    "Whether the alarm's tags are included in its action notifications and state-change events."


class AlarmActionConfiguration(TypedDict, closed=True):
    AlarmTagsPropagation: NotRequired[Expr[AlarmAlarmTagsPropagation]]
    "Whether the alarm's tags are included in its action notifications and state-change events."


class AlarmProps(TypedDict, closed=True):
    'The ``AWS::CloudWatch::Alarm`` type specifies an alarm and associates it with the specified metric or metric math expression.'
    ThresholdMetricId: NotRequired[Expr[str]]
    'In an alarm based on an anomaly detection model, this is the ID of the ``ANOMALY_DETECTION_BAND`` function used as the threshold for the alarm.'
    ComparisonOperator: NotRequired[Expr[str]]
    'The arithmetic operation to use when comparing the specified statistic and threshold.'
    EvaluationPeriods: NotRequired[Expr[int]]
    'The number of periods over which data is compared to the specified threshold.'
    Unit: NotRequired[Expr[str]]
    'The unit of the metric associated with the alarm.'
    OKActions: NotRequired[Expr[list[Expr[str]]]]
    'The actions to execute when this alarm transitions to the ``OK`` state from any other state.'
    MetricName: NotRequired[Expr[str]]
    'The name of the metric associated with the alarm.'
    ActionsEnabled: NotRequired[Expr[bool]]
    'Indicates whether actions should be executed during any changes to the alarm state.'
    Metrics: NotRequired[Expr[Sequence[Expr[AlarmMetricDataQuery]]]]
    'An array that enables you to create an alarm based on the result of a metric math expression.'
    AlarmName: NotRequired[Expr[str]]
    'The name of the alarm.'
    Statistic: NotRequired[Expr[str]]
    'The statistic for the metric associated with the alarm, other than percentile.'
    WarmUpConfiguration: NotRequired[Expr[AlarmWarmUpConfiguration]]
    'The warm-up configuration for the alarm.'
    EvaluationWindow: NotRequired[Expr[AlarmEvaluationWindow]]
    'The evaluation window that the alarm uses to select the range of metric data that it evaluates.'
    InsufficientDataActions: NotRequired[Expr[list[Expr[str]]]]
    'The actions to execute when this alarm transitions to the ``INSUFFICIENT_DATA`` state from any other state.'
    EvaluationInterval: NotRequired[Expr[int]]
    'The frequency, in seconds, at which the alarm is evaluated.'
    DatapointsToAlarm: NotRequired[Expr[int]]
    'The number of datapoints that must be breaching to trigger the alarm.'
    Tags: NotRequired[Expr[Sequence[Expr[Tag]]]]
    'A list of key-value pairs to associate with the alarm.'
    Threshold: NotRequired[Expr[float]]
    'The value to compare with the specified statistic.'
    EvaluateLowSampleCountPercentile: NotRequired[Expr[str]]
    'Used only for alarms based on percentiles.'
    ExtendedStatistic: NotRequired[Expr[str]]
    'The percentile statistic for the metric associated with the alarm.'
    TreatMissingData: NotRequired[Expr[str]]
    'Sets how this alarm is to handle missing data points.'
    Dimensions: NotRequired[Expr[Sequence[Expr[AlarmDimension]]]]
    'The dimensions for the metric associated with the alarm.'
    Period: NotRequired[Expr[int]]
    'The period, in seconds, over which the statistic is applied.'
    EvaluationCriteria: NotRequired[Expr[AlarmEvaluationCriteria]]
    'The evaluation criteria for the alarm.'
    Namespace: NotRequired[Expr[str]]
    'The namespace of the metric associated with the alarm.'
    AlarmActions: NotRequired[Expr[list[Expr[str]]]]
    'The list of actions to execute when this alarm transitions into an ALARM state from any other state.'
    AlarmDescription: NotRequired[Expr[str]]
    'The description of the alarm.'
    ActionConfiguration: NotRequired[Expr[AlarmActionConfiguration]]


class Alarm(ResourceAttrs):
    'The ``AWS::CloudWatch::Alarm`` type specifies an alarm and associates it with the specified metric or metric math expression.'
    Type: Literal['AWS::CloudWatch::Alarm']
    Properties: NotRequired[AlarmProps]


def alarm(
    *,
    depends_on: DependsOn | None = None,
    deletion_policy: DeletionPolicy | None = None,
    update_replace_policy: UpdateReplacePolicy | None = None,
    condition: str | None = None,
    metadata: dict[str, Any] | None = None,
    **props: Unpack[AlarmProps],
) -> Alarm:
    return build('AWS::CloudWatch::Alarm', props, depends_on, deletion_policy, update_replace_policy, condition, metadata)

Attributes

Read-only values for get_att(logical_id, attribute). They are not accepted as inputs.

  • Arn