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.

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.

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.

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:

CloudWatch Logs Resource Browser -CloudWatch Metrics Resource Browser
  • 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:

Last modified July 18, 2024: setup markdownlint (#1382) (f2ebb421e)