Skip to content

put_log_alarm async

put_log_alarm(
    *,
    config_overrides: Optional[AsyncCloudWatchClientConfig] = None,
    alarm_name: Optional[AlarmName] = None,
    alarm_description: Optional[AlarmDescription] = None,
    scheduled_query_configuration: Optional[ScheduledQueryConfiguration] = None,
    action_log_line_count: Optional[ActionLogLineCount] = None,
    action_log_line_role_arn: Optional[ActionLogLineRoleArn] = None,
    actions_enabled: Optional[ActionsEnabled] = None,
    ok_actions: Optional[ResourceList] = None,
    alarm_actions: Optional[ResourceList] = None,
    insufficient_data_actions: Optional[ResourceList] = None,
    query_results_to_evaluate: Optional[QueryResultsToEvaluate] = None,
    query_results_to_alarm: Optional[QueryResultsToAlarm] = None,
    threshold: Optional[Threshold] = None,
    comparison_operator: Optional[ComparisonOperator] = None,
    treat_missing_data: Optional[TreatMissingData] = None,
    tags: Optional[TagList] = None,
    warm_up_configuration: Optional[WarmUpConfiguration] = None,
) -> None

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.

Parameters:

  • alarm_name (Optional[AlarmName], default: None ) –

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

  • alarm_description (Optional[AlarmDescription], default: None ) –

    The description for the alarm.

  • scheduled_query_configuration (Optional[ScheduledQueryConfiguration], default: None ) –

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

  • action_log_line_count (Optional[ActionLogLineCount], default: None ) –

    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.

  • action_log_line_role_arn (Optional[ActionLogLineRoleArn], default: None ) –

    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.

  • actions_enabled (Optional[ActionsEnabled], default: None ) –

    Indicates whether actions should be executed during any changes to the alarm state. The default is true.

  • ok_actions (Optional[ResourceList], default: None ) –

    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

  • alarm_actions (Optional[ResourceList], default: None ) –

    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

  • insufficient_data_actions (Optional[ResourceList], default: None ) –

    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

  • query_results_to_evaluate (Optional[QueryResultsToEvaluate], default: None ) –

    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.

  • query_results_to_alarm (Optional[QueryResultsToAlarm], default: None ) –

    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 (Optional[Threshold], default: None ) –

    The value to compare with the aggregated query result.

  • comparison_operator (Optional[ComparisonOperator], default: None ) –

    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.

  • treat_missing_data (Optional[TreatMissingData], default: None ) –

    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 (Optional[TagList], default: None ) –

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

  • warm_up_configuration (Optional[WarmUpConfiguration], default: None ) –

    The warm-up configuration for the alarm. A warm-up period delays alarm evaluation after you create or update the alarm. The warm-up period reduces alarm noise from missing data while a new resource or service starts publishing data.

    For more information, see Alarm warm-up periods in the Amazon CloudWatch User Guide.

Raises:

  • LimitExceededFault –

    The quota for alarms for this customer has already been reached.

  • ResourceConflict –

    The operation could not be completed because the request conflicts with the current state of the alarm or its underlying scheduled query resource.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_cloudwatch/_services/async_cloud_watch.py
async def put_log_alarm(
    self,
    *,
    config_overrides: Optional[AsyncCloudWatchClientConfig] = None,
    alarm_name: Optional["capo_cloudwatch.types.alarm_name.AlarmName"] = None,
    alarm_description: Optional[
        "capo_cloudwatch.types.alarm_description.AlarmDescription"
    ] = None,
    scheduled_query_configuration: Optional[
        "capo_cloudwatch.types.scheduled_query_configuration.ScheduledQueryConfiguration"
    ] = None,
    action_log_line_count: Optional[
        "capo_cloudwatch.types.action_log_line_count.ActionLogLineCount"
    ] = None,
    action_log_line_role_arn: Optional[
        "capo_cloudwatch.types.action_log_line_role_arn.ActionLogLineRoleArn"
    ] = None,
    actions_enabled: Optional[
        "capo_cloudwatch.types.actions_enabled.ActionsEnabled"
    ] = None,
    ok_actions: Optional["capo_cloudwatch.types.resource_list.ResourceList"] = None,
    alarm_actions: Optional[
        "capo_cloudwatch.types.resource_list.ResourceList"
    ] = None,
    insufficient_data_actions: Optional[
        "capo_cloudwatch.types.resource_list.ResourceList"
    ] = None,
    query_results_to_evaluate: Optional[
        "capo_cloudwatch.types.query_results_to_evaluate.QueryResultsToEvaluate"
    ] = None,
    query_results_to_alarm: Optional[
        "capo_cloudwatch.types.query_results_to_alarm.QueryResultsToAlarm"
    ] = None,
    threshold: Optional["capo_cloudwatch.types.threshold.Threshold"] = None,
    comparison_operator: Optional[
        "capo_cloudwatch.types.comparison_operator.ComparisonOperator"
    ] = None,
    treat_missing_data: Optional[
        "capo_cloudwatch.types.treat_missing_data.TreatMissingData"
    ] = None,
    tags: Optional["capo_cloudwatch.types.tag_list.TagList"] = None,
    warm_up_configuration: Optional[
        "capo_cloudwatch.types.warm_up_configuration.WarmUpConfiguration"
    ] = None,
) -> None:
    """<p>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.</p> <p>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 <code>AggregationExpression</code>, and each aggregated value is compared against the alarm <code>Threshold</code> to determine the alarm state. The alarm uses M-out-of-N evaluation: if <code>QueryResultsToAlarm</code> out of the most recent <code>QueryResultsToEvaluate</code> query results breach the threshold, the alarm transitions to <code>ALARM</code>.</p> <p>Log alarms support the alarm states (<code>OK</code>, <code>ALARM</code>, <code>INSUFFICIENT_DATA</code>). Configure transition actions using <code>OKActions</code>, <code>AlarmActions</code>, and <code>InsufficientDataActions</code>.</p> <p>If you call this operation with the name of an existing log alarm, the operation replaces the previous configuration of that alarm.</p> <p> <b>Permissions</b> </p> <p>To create or update a log alarm, you must have the <code>cloudwatch:PutLogAlarm</code> permission. The IAM role specified in <code>ScheduledQueryRoleARN</code> must grant the CloudWatch Alarms service permission to execute scheduled queries on the specified log groups. If you set <code>ActionLogLineCount</code>, the role specified in <code>ActionLogLineRoleArn</code> must grant permission to retrieve log events for inclusion in alarm notifications.</p>

    Args:
        alarm_name: <p>The name for the alarm. This name must be unique within the Amazon Web Services account and Region.</p>
        alarm_description: <p>The description for the alarm.</p>
        scheduled_query_configuration: <p>The configuration of the underlying CloudWatch Logs scheduled query that this alarm evaluates, including the query string, log groups, schedule, and aggregation expression.</p>
        action_log_line_count: <p>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.</p>
        action_log_line_role_arn: <p>The Amazon Resource Name (ARN) of an IAM role that CloudWatch assumes to retrieve log events for inclusion in alarm action notifications. Required when <code>ActionLogLineCount</code> is greater than 0.</p>
        actions_enabled: <p>Indicates whether actions should be executed during any changes to the alarm state. The default is <code>true</code>.</p>
        ok_actions: <p>The actions to execute when this alarm transitions to the <code>OK</code> state from any other state. Each action is specified as an Amazon Resource Name (ARN).</p> <p>Valid Values:</p> <p> <b>Amazon SNS actions:</b> </p> <p> <code>arn:aws:sns:<i>region</i>:<i>account-id</i>:<i>sns-topic-name</i> </code> </p> <p> <b>Lambda actions:</b> </p> <ul> <li> <p>Invoke the latest version of a Lambda function: <code>arn:aws:lambda:<i>region</i>:<i>account-id</i>:function:<i>function-name</i> </code> </p> </li> <li> <p>Invoke a specific version of a Lambda function: <code>arn:aws:lambda:<i>region</i>:<i>account-id</i>:function:<i>function-name</i>:<i>version-number</i> </code> </p> </li> <li> <p>Invoke a function by using an alias Lambda function: <code>arn:aws:lambda:<i>region</i>:<i>account-id</i>:function:<i>function-name</i>:<i>alias-name</i> </code> </p> </li> </ul>
        alarm_actions: <p>The actions to execute when this alarm transitions to the <code>ALARM</code> state from any other state. Each action is specified as an Amazon Resource Name (ARN).</p> <p>Valid Values:</p> <p> <b>Amazon SNS actions:</b> </p> <p> <code>arn:aws:sns:<i>region</i>:<i>account-id</i>:<i>sns-topic-name</i> </code> </p> <p> <b>Lambda actions:</b> </p> <ul> <li> <p>Invoke the latest version of a Lambda function: <code>arn:aws:lambda:<i>region</i>:<i>account-id</i>:function:<i>function-name</i> </code> </p> </li> <li> <p>Invoke a specific version of a Lambda function: <code>arn:aws:lambda:<i>region</i>:<i>account-id</i>:function:<i>function-name</i>:<i>version-number</i> </code> </p> </li> <li> <p>Invoke a function by using an alias Lambda function: <code>arn:aws:lambda:<i>region</i>:<i>account-id</i>:function:<i>function-name</i>:<i>alias-name</i> </code> </p> </li> </ul> <p> <b>Systems Manager actions:</b> </p> <p> <code>arn:aws:ssm:<i>region</i>:<i>account-id</i>:opsitem:<i>severity</i> </code> </p>
        insufficient_data_actions: <p>The actions to execute when this alarm transitions to the <code>INSUFFICIENT_DATA</code> state from any other state. Each action is specified as an Amazon Resource Name (ARN).</p> <p>Valid Values:</p> <p> <b>Amazon SNS actions:</b> </p> <p> <code>arn:aws:sns:<i>region</i>:<i>account-id</i>:<i>sns-topic-name</i> </code> </p> <p> <b>Lambda actions:</b> </p> <ul> <li> <p>Invoke the latest version of a Lambda function: <code>arn:aws:lambda:<i>region</i>:<i>account-id</i>:function:<i>function-name</i> </code> </p> </li> <li> <p>Invoke a specific version of a Lambda function: <code>arn:aws:lambda:<i>region</i>:<i>account-id</i>:function:<i>function-name</i>:<i>version-number</i> </code> </p> </li> <li> <p>Invoke a function by using an alias Lambda function: <code>arn:aws:lambda:<i>region</i>:<i>account-id</i>:function:<i>function-name</i>:<i>alias-name</i> </code> </p> </li> </ul>
        query_results_to_evaluate: <p>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.</p>
        query_results_to_alarm: <p>The number of query results, out of the most recent <code>QueryResultsToEvaluate</code> results, that must breach the threshold to trigger the alarm to transition to <code>ALARM</code> (the M in M-of-N evaluation). Must be less than or equal to <code>QueryResultsToEvaluate</code>.</p>
        threshold: <p>The value to compare with the aggregated query result.</p>
        comparison_operator: <p>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 <code>GreaterThanThreshold</code>, <code>GreaterThanOrEqualToThreshold</code>, <code>LessThanThreshold</code>, and <code>LessThanOrEqualToThreshold</code>.</p>
        treat_missing_data: <p>Sets how this alarm is to handle missing data points. Valid values are <code>breaching</code>, <code>notBreaching</code>, <code>ignore</code>, and <code>missing</code>. If this parameter is omitted, the default behavior of <code>missing</code> is used.</p>
        tags: <p>A list of key-value pairs to associate with the alarm. You can use tags to categorize and manage your alarms.</p>
        warm_up_configuration: <p>The warm-up configuration for the alarm. A warm-up period delays alarm evaluation after you create or update the alarm. The warm-up period reduces alarm noise from missing data while a new resource or service starts publishing data.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/alarm-warm-up.html">Alarm warm-up periods</a> in the <i>Amazon CloudWatch User Guide</i>.</p>

    Raises:
        capo_cloudwatch.errors.limit_exceeded_fault.LimitExceededFault: <p>The quota for alarms for this customer has already been reached.</p>
        capo_cloudwatch.errors.resource_conflict.ResourceConflict: <p>The operation could not be completed because the request conflicts with the current state of the alarm or its underlying scheduled query resource.</p>
        capo_cloudwatch.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_cloudwatch.types.put_log_alarm_input.PutLogAlarmInput]",
    ) -> AsyncOperationResponse[None]:
        import capo_cloudwatch._operations.granite_service_version20100801.put_log_alarm

        (
            output,
            http_response,
        ) = await capo_cloudwatch._operations.granite_service_version20100801.put_log_alarm.async_put_log_alarm(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutLogAlarm")
    )
    input_: capo_cloudwatch.types.put_log_alarm_input.PutLogAlarmInput = {}
    if alarm_name is not None:
        input_["alarm_name"] = alarm_name
    if alarm_description is not None:
        input_["alarm_description"] = alarm_description
    if scheduled_query_configuration is not None:
        input_["scheduled_query_configuration"] = scheduled_query_configuration
    if action_log_line_count is not None:
        input_["action_log_line_count"] = action_log_line_count
    if action_log_line_role_arn is not None:
        input_["action_log_line_role_arn"] = action_log_line_role_arn
    if actions_enabled is not None:
        input_["actions_enabled"] = actions_enabled
    if ok_actions is not None:
        input_["ok_actions"] = ok_actions
    if alarm_actions is not None:
        input_["alarm_actions"] = alarm_actions
    if insufficient_data_actions is not None:
        input_["insufficient_data_actions"] = insufficient_data_actions
    if query_results_to_evaluate is not None:
        input_["query_results_to_evaluate"] = query_results_to_evaluate
    if query_results_to_alarm is not None:
        input_["query_results_to_alarm"] = query_results_to_alarm
    if threshold is not None:
        input_["threshold"] = threshold
    if comparison_operator is not None:
        input_["comparison_operator"] = comparison_operator
    if treat_missing_data is not None:
        input_["treat_missing_data"] = treat_missing_data
    if tags is not None:
        input_["tags"] = tags
    if warm_up_configuration is not None:
        input_["warm_up_configuration"] = warm_up_configuration

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output