CloudWatch / Client / put_log_alarm

put_log_alarm

CloudWatch.Client.put_log_alarm(**kwargs)

Creates or updates a log alarm. A log alarm evaluates the results of a CloudWatch Logs scheduled query against the configured threshold and comparison operator to determine its state.

When you create a log alarm, the operation creates a service-managed CloudWatch Logs scheduled query that runs the query string you provide on the schedule you configure. Each scheduled query execution returns one or more aggregated values determined by the AggregationExpression, and each aggregated value is compared against the alarm Threshold to determine the alarm state. The alarm uses M-out-of-N evaluation: if QueryResultsToAlarm out of the most recent QueryResultsToEvaluate query results breach the threshold, the alarm transitions to ALARM.

Log alarms support the alarm states ( OK, ALARM, INSUFFICIENT_DATA). Configure transition actions using OKActions, AlarmActions, and InsufficientDataActions.

If you call this operation with the name of an existing log alarm, the operation replaces the previous configuration of that alarm.

Permissions

To create or update a log alarm, you must have the cloudwatch:PutLogAlarm permission. The IAM role specified in ScheduledQueryRoleARN must grant the CloudWatch Alarms service permission to execute scheduled queries on the specified log groups. If you set ActionLogLineCount, the role specified in ActionLogLineRoleArn must grant permission to retrieve log events for inclusion in alarm notifications.

See also: AWS API Documentation

Request Syntax

response = client.put_log_alarm(
    AlarmName='string',
    AlarmDescription='string',
    ScheduledQueryConfiguration={
        'QueryString': 'string',
        'LogGroupIdentifiers': [
            'string',
        ],
        'QueryARN': 'string',
        'ScheduledQueryRoleARN': 'string',
        'ScheduleConfiguration': {
            'ScheduleExpression': 'string',
            'StartTimeOffset': 123,
            'EndTimeOffset': 123
        },
        'AggregationExpression': 'string',
        'Tags': [
            {
                'Key': 'string',
                'Value': 'string'
            },
        ]
    },
    ActionLogLineCount=123,
    ActionLogLineRoleArn='string',
    ActionsEnabled=True|False,
    OKActions=[
        'string',
    ],
    AlarmActions=[
        'string',
    ],
    InsufficientDataActions=[
        'string',
    ],
    QueryResultsToEvaluate=123,
    QueryResultsToAlarm=123,
    Threshold=123.0,
    ComparisonOperator='GreaterThanOrEqualToThreshold'|'GreaterThanThreshold'|'LessThanThreshold'|'LessThanOrEqualToThreshold'|'LessThanLowerOrGreaterThanUpperThreshold'|'LessThanLowerThreshold'|'GreaterThanUpperThreshold',
    TreatMissingData='string',
    Tags=[
        {
            'Key': 'string',
            'Value': 'string'
        },
    ]
)
Parameters:
  • AlarmName (string) –

    [REQUIRED]

    The name for the alarm. This name must be unique within the Amazon Web Services account and Region.

  • AlarmDescription (string) – The description for the alarm.

  • ScheduledQueryConfiguration (dict) –

    [REQUIRED]

    The configuration of the underlying CloudWatch Logs scheduled query that this alarm evaluates, including the query string, log groups, schedule, and aggregation expression.

    • QueryString (string) – [REQUIRED]

      The CloudWatch Logs query to execute on each scheduled run. Length constraints: maximum of 10,000 characters.

    • LogGroupIdentifiers (list) –

      The log groups to query. Each entry can be a log group name or ARN. Use the ARN form when querying log groups in a different account (for example, when running cross-account queries from a monitoring account). The list must contain between 1 and 50 entries.

      • (string) –

    • QueryARN (string) –

      The Amazon Resource Name (ARN) of the CloudWatch Logs scheduled query that the alarm uses. This field is populated in DescribeAlarms responses.

    • ScheduledQueryRoleARN (string) – [REQUIRED]

      The Amazon Resource Name (ARN) of the IAM role that CloudWatch assumes when executing the scheduled query against the configured log groups.

    • ScheduleConfiguration (dict) – [REQUIRED]

      The schedule and time-range offset configuration for the underlying scheduled query.

      • ScheduleExpression (string) – [REQUIRED]

        The schedule expression that defines how often the underlying CloudWatch Logs scheduled query runs. Specify a rate() expression, for example rate(5 minutes).

      • StartTimeOffset (integer) –

        The offset, in seconds, before the scheduled execution time at which the query time range begins. For example, an offset of 360 (6 minutes) on a query running at 12:05:00 starts the query time range at 11:59:00.

      • EndTimeOffset (integer) –

        The offset, in seconds, before the scheduled execution time at which the query time range ends. Must be non-negative and less than StartTimeOffset. The default is 0.

    • AggregationExpression (string) – [REQUIRED]

      The expression that defines how to aggregate query results into one or more scalar values for alarm evaluation. For example, count(*) or avg(latency) by host | sort desc. Length constraints: minimum 1 character, maximum 2048 characters.

    • Tags (list) –

      A list of key-value pairs to associate with the underlying scheduled query resource.

      • (dict) –

        A key-value pair associated with a CloudWatch resource.

        • Key (string) – [REQUIRED]

          A string that you can use to assign a value. The combination of tag keys and values can help you organize and categorize your resources.

        • Value (string) – [REQUIRED]

          The value for the specified tag key.

  • ActionLogLineCount (integer) – The number of log lines from the most recent scheduled query execution to include in alarm action notifications. Valid range is 0 through 50. The default is 0, which means no log lines are included.

  • ActionLogLineRoleArn (string) – The Amazon Resource Name (ARN) of an IAM role that CloudWatch assumes to retrieve log events for inclusion in alarm action notifications. Required when ActionLogLineCount is greater than 0.

  • ActionsEnabled (boolean) – Indicates whether actions should be executed during any changes to the alarm state. The default is true.

  • OKActions (list) –

    The actions to execute when this alarm transitions to the OK state from any other state. Each action is specified as an Amazon Resource Name (ARN).

    Valid Values:

    Amazon SNS actions:

    arn:aws:sns:region:account-id:sns-topic-name

    Lambda actions:

    • Invoke the latest version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name

    • Invoke a specific version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name:version-number

    • Invoke a function by using an alias Lambda function: arn:aws:lambda:region:account-id:function:function-name:alias-name

    • (string) –

  • AlarmActions (list) –

    The actions to execute when this alarm transitions to the ALARM state from any other state. Each action is specified as an Amazon Resource Name (ARN).

    Valid Values:

    Amazon SNS actions:

    arn:aws:sns:region:account-id:sns-topic-name

    Lambda actions:

    • Invoke the latest version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name

    • Invoke a specific version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name:version-number

    • Invoke a function by using an alias Lambda function: arn:aws:lambda:region:account-id:function:function-name:alias-name

    Systems Manager actions:

    arn:aws:ssm:region:account-id:opsitem:severity

    • (string) –

  • InsufficientDataActions (list) –

    The actions to execute when this alarm transitions to the INSUFFICIENT_DATA state from any other state. Each action is specified as an Amazon Resource Name (ARN).

    Valid Values:

    Amazon SNS actions:

    arn:aws:sns:region:account-id:sns-topic-name

    Lambda actions:

    • Invoke the latest version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name

    • Invoke a specific version of a Lambda function: arn:aws:lambda:region:account-id:function:function-name:version-number

    • Invoke a function by using an alias Lambda function: arn:aws:lambda:region:account-id:function:function-name:alias-name

    • (string) –

  • QueryResultsToEvaluate (integer) –

    [REQUIRED]

    The number of most recent scheduled query results to evaluate against the threshold (the N in M-of-N evaluation). Valid range is 1 through 100.

  • QueryResultsToAlarm (integer) –

    [REQUIRED]

    The number of query results, out of the most recent QueryResultsToEvaluate results, that must breach the threshold to trigger the alarm to transition to ALARM (the M in M-of-N evaluation). Must be less than or equal to QueryResultsToEvaluate.

  • Threshold (float) –

    [REQUIRED]

    The value to compare with the aggregated query result.

  • ComparisonOperator (string) –

    [REQUIRED]

    The arithmetic operation to use when comparing the aggregated query result and the threshold. The aggregated query result is used as the first operand. Valid values are GreaterThanThreshold, GreaterThanOrEqualToThreshold, LessThanThreshold, and LessThanOrEqualToThreshold.

  • TreatMissingData (string) – Sets how this alarm is to handle missing data points. Valid values are breaching, notBreaching, ignore, and missing. If this parameter is omitted, the default behavior of missing is used.

  • Tags (list) –

    A list of key-value pairs to associate with the alarm. You can use tags to categorize and manage your alarms.

    • (dict) –

      A key-value pair associated with a CloudWatch resource.

      • Key (string) – [REQUIRED]

        A string that you can use to assign a value. The combination of tag keys and values can help you organize and categorize your resources.

      • Value (string) – [REQUIRED]

        The value for the specified tag key.

Returns:

None

Exceptions

  • CloudWatch.Client.exceptions.LimitExceededFault

  • CloudWatch.Client.exceptions.ResourceConflict