CloudWatch
Get started with AWS CloudWatch on LocalStack
CloudWatch is a comprehensive monitoring and observability service that Amazon Web Services (AWS) provides.
It allows you to collect and track metrics, collect and monitor log files, and set alarms.
CloudWatch provides valuable insights into your AWS resources, applications, and services, enabling you to troubleshoot issues, optimize performance, and make informed decisions.
LocalStack allows you to use CloudWatch APIs on your local machine to create and manage CloudWatch resources, such as custom metrics, alarms, and log groups, for local development and testing purposes.
-The supported APIs are available on our API coverage page, which provides information on the extent of CloudWatch’s integration with LocalStack.
Note
We have introduced an all-new LocalStack-native CloudWatch provider is available behind a feature flag.
-You can activate it by configuring PROVIDER_OVERRIDE_CLOUDWATCH=v2
in your LocalStack configuration.
We have migrated from storing data in Python objects within the Moto backend to a more robust system.
-Now, metrics are efficiently stored in SQLite, and alarm resources are managed using LocalStack stores.
- Various enhancements have been made to attain greater feature parity with AWS.
- The provider is engineered to ensure thread safety, facilitating smooth concurrent operations.
- There’s a significant improvement in the integrity and durability of data.
- The new provider allows for more efficient data retrieval.
Getting started
This guide is designed for users new to CloudWatch and assumes basic knowledge of the AWS CLI and our awslocal
wrapper script.
Start your LocalStack container using your preferred method and deploy your Lambda functions that will generate some logs.
+The supported APIs are available on our API coverage page, which provides information on the extent of CloudWatch’s integration with LocalStack.
Note
We have introduced an all-new LocalStack-native CloudWatch provider and recently made this one the default.
With the new provider we have migrated from storing data in Python objects within the Moto backend to a more robust system.
Now, metrics are efficiently stored in SQLite, and alarm resources are managed using LocalStack stores.
- Various enhancements have been made to attain greater feature parity with AWS.
- The provider is engineered to ensure thread safety, facilitating smooth concurrent operations.
- There’s a significant improvement in the integrity and durability of data.
- The new provider allows for more efficient data retrieval.
Currently, it is still possible to switch back to the old provider using PROVIDER_OVERRIDE_CLOUDWATCH=v1
in your LocalStack configuration.
Getting started
This guide is designed for users new to CloudWatch and assumes basic knowledge of the AWS CLI and our awslocal
wrapper script.
Start your LocalStack container using your preferred method and deploy your Lambda functions that will generate some logs.
You can get the name for your Lambda Functions using the ListFunctions
API.
Fetch the Log Groups using the DescribeLogGroups
API.
Run the following command to get the Log Group name:
$ awslocal logs describe-log-groups
The output should look similar to the following:
{
"logGroups": [
@@ -418,4 +416,4 @@
--alarm-actions <topic-arn>
By executing this command, you’ll create an alarm named my-alarm
that monitors the Orders
metric in the test
namespace.
If the metric value exceeds the threshold of 50 (using the GreaterThanThreshold
operator) during a single evaluation period of 300 seconds, the alarm will trigger the specified action on the provided SNS topic.
Warning
Please be aware of the following known limitations in LocalStack:
- Anomaly detection and extended statistics are not supported.
- The
unit
values specified in the alarm are ignored. - Composite alarms are not evaluated.
- Metric streams are not supported.
Supported Service Integrations with CloudWatch Metrics
LocalStack supports the following AWS services for integration with CloudWatch metrics:
- SQS: Supports
Approximate*
metrics, NumberOfMessagesSent
, and other metrics triggered by events such as message received or sending. - Lambda: Supports
Invocations
and Errors
metrics.
Resource Browser
The LocalStack Web Application provides a Resource Browser for managing CloudWatch logs.
You can access the Resource Browser by opening the LocalStack Web Application in your browser and navigating to the Resources section, then clicking on CloudWatch Logs and CloudWatch Metrics under the Management/Governance section.
The Resource Browser allows you to perform the following actions:
-
- Create Log Group: Create a new log group by specifying the
Log Group Name
, KMS Key ID
, and Tags
. - Put metric: Create a new metric by specifying the
Namespace
and Metric Data
. - Put Alarm: Create a new alarm by specifying the
Alarm Name
, Alarm Description
, Actions Enabled
, Metric Name
, Namespace
, Statistic
, Comparison Operator
, Threshold
, Evaluation Periods
, Period
, Unit
, Treat Missing Data
, Tags
, and Alarm Actions
. - Check the Resources: View and manage existing log groups, metrics, and alarms and perform actions such as
Delete
, View
, and Edit
.
Examples
The following code snippets and sample applications provide practical examples of how to use CloudWatch in LocalStack for various use cases: