Shows how to use the AWS SDK for Python (Boto3) to work with Amazon CloudWatch.
CloudWatch provides a reliable, scalable, and flexible monitoring solution that you can start using within minutes.
- Running this code might result in charges to your AWS account. For more details, see AWS Pricing and Free Tier.
- Running the tests might result in charges to your AWS account.
- We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
- This code is not tested in every AWS Region. For more information, see AWS Regional Services.
For prerequisites, see the README in the python folder.
Install the packages required by these examples by running the following in a virtual environment:
python -m pip install -r requirements.txt
Code examples that show you how to perform the essential operations within a service.
Code excerpts that show you how to call individual service functions.
- DeleteAlarmMuteRule
- DeleteAlarms
- DescribeAlarmContributors
- DescribeAlarmsForMetric
- DisableAlarmActions
- EnableAlarmActions
- GetAlarmMuteRule
- GetMetricStatistics
- GetOTelEnrichment
- ListAlarmMuteRules
- ListMetrics
- PutAlarmMuteRule
- PutMetricAlarm
- PutMetricData
- StartOTelEnrichment
- StopOTelEnrichment
Code examples that show you how to accomplish a specific task by calling multiple functions within the same service.
This example shows you how to do the following:
- List CloudWatch namespaces and metrics.
- Start OpenTelemetry enrichment so CloudWatch correlates incoming OTLP metrics with the resources that produced them.
- See how OTLP metrics reach the CloudWatch metrics endpoint. Metric ingestion over OTLP is not an AWS SDK operation.
- Create an alarm that evaluates a PromQL query.
- Inspect the alarm's contributors, the individual series that the query matched.
- Get statistics for a metric and chart it on a dashboard.
- Mute the alarm for a maintenance window, then clean up.
Start the example by running the following at a command prompt:
python cloudwatch_scenario.py
This example shows you how to do the following:
- Create an alarm to watch a single CloudWatch metric.
- Put data into the metric with
PutMetricDataand trigger the alarm. - Get data from the alarm.
- Delete the alarm.
Start the example by running the following at a command prompt:
python cloudwatch_basics.py
This example shows you how to do the following:
- Send OTLP metrics to the CloudWatch metrics endpoint with an OpenTelemetry Collector.
- Start OpenTelemetry enrichment so CloudWatch correlates those metrics with your resources.
- Create an alarm that evaluates a PromQL query across every series the query returns.
- Inspect the individual series, called contributors, that put the alarm in ALARM state.
- Mute the alarm for a maintenance window, then clean up.
Start the example by running the following at a command prompt:
python cloudwatch_otel.py
⚠ Running tests might result in charges to your AWS account.
To find instructions for running these tests, see the README
in the python folder.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0