Creates or updates a log alarm¶
Description¶
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.
Usage¶
cloudwatch_put_log_alarm(AlarmName, AlarmDescription,
ScheduledQueryConfiguration, ActionLogLineCount, ActionLogLineRoleArn,
ActionsEnabled, OKActions, AlarmActions, InsufficientDataActions,
QueryResultsToEvaluate, QueryResultsToAlarm, Threshold,
ComparisonOperator, TreatMissingData, Tags, WarmUpConfiguration)
Arguments¶
-
AlarmName[required] The name for the alarm. This name must be unique within the Amazon Web Services account and Region.
-
AlarmDescriptionThe description for the alarm.
-
ScheduledQueryConfiguration[required] The configuration of the underlying CloudWatch Logs scheduled query that this alarm evaluates, including the query string, log groups, schedule, and aggregation expression.
-
ActionLogLineCountThe 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.
-
ActionLogLineRoleArnThe Amazon Resource Name (ARN) of an IAM role that CloudWatch assumes to retrieve log events for inclusion in alarm action notifications. Required when
ActionLogLineCountis greater than 0. -
ActionsEnabledIndicates whether actions should be executed during any changes to the alarm state. The default is
true. -
OKActionsThe actions to execute when this alarm transitions to the
OKstate 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-nameLambda 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
- Invoke the latest version of a Lambda function:
-
AlarmActionsThe actions to execute when this alarm transitions to the
ALARMstate 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-nameLambda 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 - Invoke the latest version of a Lambda function:
-
InsufficientDataActionsThe actions to execute when this alarm transitions to the
INSUFFICIENT_DATAstate 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-nameLambda 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
- Invoke the latest version of a Lambda function:
-
QueryResultsToEvaluate[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[required] The number of query results, out of the most recent
QueryResultsToEvaluateresults, that must breach the threshold to trigger the alarm to transition toALARM(the M in M-of-N evaluation). Must be less than or equal toQueryResultsToEvaluate. -
Threshold[required] The value to compare with the aggregated query result.
-
ComparisonOperator[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, andLessThanOrEqualToThreshold. -
TreatMissingDataSets how this alarm is to handle missing data points. Valid values are
breaching,notBreaching,ignore, andmissing. If this parameter is omitted, the default behavior ofmissingis used. -
TagsA list of key-value pairs to associate with the alarm. You can use tags to categorize and manage your alarms.
-
WarmUpConfigurationThe 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.
Value¶
An empty list.
Request syntax¶
svc$put_log_alarm(
AlarmName = "string",
AlarmDescription = "string",
ScheduledQueryConfiguration = list(
QueryString = "string",
LogGroupIdentifiers = list(
"string"
),
QueryARN = "string",
ScheduledQueryRoleARN = "string",
ScheduleConfiguration = list(
ScheduleExpression = "string",
StartTimeOffset = 123,
EndTimeOffset = 123
),
AggregationExpression = "string",
Tags = list(
list(
Key = "string",
Value = "string"
)
)
),
ActionLogLineCount = 123,
ActionLogLineRoleArn = "string",
ActionsEnabled = TRUE|FALSE,
OKActions = list(
"string"
),
AlarmActions = list(
"string"
),
InsufficientDataActions = list(
"string"
),
QueryResultsToEvaluate = 123,
QueryResultsToAlarm = 123,
Threshold = 123.0,
ComparisonOperator = "GreaterThanOrEqualToThreshold"|"GreaterThanThreshold"|"LessThanThreshold"|"LessThanOrEqualToThreshold"|"LessThanLowerOrGreaterThanUpperThreshold"|"LessThanLowerThreshold"|"GreaterThanUpperThreshold",
TreatMissingData = "string",
Tags = list(
list(
Key = "string",
Value = "string"
)
),
WarmUpConfiguration = list(
WarmUpPeriodDurationInMinutes = 123,
OnlyStartEvaluatingAfterWarmUpPeriodEnds = TRUE|FALSE
)
)