LinuxCommandLibrary

aws-cloudwatch

Manage and monitor AWS CloudWatch resources

TLDR

List dashboards for your account

$ aws cloudwatch list-dashboards
copy

Display details for the specified dashboard
$ aws cloudwatch get-dashboard --dashboard-name [dashboard_name]
copy

List metrics
$ aws cloudwatch list-metrics
copy

List alarms
$ aws cloudwatch describe-alarms
copy

Create or update an alarm and associate it with a metric
$ aws cloudwatch put-metric-alarm --alarm-name [alarm_name] --evaluation-periods [evaluation_periods] --comparison-operator [comparison_operator]
copy

Delete the specified alarms
$ aws cloudwatch delete-alarms --alarm_names [alarm_names]
copy

Delete the specified dashboards
$ aws cloudwatch delete-dashboards --dashboard-names [dashboard_names]
copy

SYNOPSIS

aws cloudwatch command [options]

Examples:
aws cloudwatch put-metric-data --metric-name MyMetric --namespace MyApplication --value 10
aws cloudwatch get-metric-statistics --metric-name CPUUtilization --namespace AWS/EC2 --start-time YYYY-MM-DDTHH:MM:SSZ --end-time YYYY-MM-DDTHH:MM:SSZ --period 300 --statistics Average
aws cloudwatch describe-alarms --state-value ALARM

PARAMETERS

--region region-name
    Specifies the AWS region to send the request to. Overrides configured region.

--output format
    Specifies the output format (e.g., json, text, table).

--profile profile-name
    Specifies a named profile to use from your AWS credentials file.

--endpoint-url url
    Specifies a custom endpoint for the CloudWatch service.

--cli-input-json file://path/to/file.json
    Reads arguments from a JSON file, allowing complex input structures.

--query expression
    Uses JMESPath to filter and format the output of a command.

--debug
    Turns on debug logging for the command execution.

Command-specific options
    Each CloudWatch sub-command (e.g., put-metric-data, get-log-events) has its own set of required and optional parameters, such as metric names, namespaces, timestamps, log group names, filter patterns, and more. These are highly specific to the operation being performed and are too numerous to list exhaustively here.

DESCRIPTION

The aws cloudwatch command is a sub-command of the AWS Command Line Interface (CLI), providing a powerful way to manage and interact with Amazon CloudWatch directly from your terminal. CloudWatch is a monitoring and observability service that provides data and actionable insights to monitor your applications, understand and respond to system-wide performance changes, and optimize resource utilization. Using the aws cloudwatch command, users can perform a variety of operations, including publishing custom metrics, retrieving statistics for existing metrics, setting up and describing alarms, fetching logs from CloudWatch Logs, and managing dashboards. This command is essential for scripting automated tasks, integrating monitoring into CI/CD pipelines, and performing quick diagnostics and data retrieval without needing to access the AWS Management Console.

CAVEATS

Requires the AWS CLI to be installed and configured with appropriate AWS credentials (access key ID and secret access key) and default region.
Users must have sufficient IAM permissions to perform the requested CloudWatch operations.
API calls are subject to AWS service limits and throttling.

AUTHENTICATION AND CONFIGURATION

Before using aws cloudwatch, ensure your AWS CLI is configured. This typically involves running aws configure to set up your access key ID, secret access key, default region, and output format. Credentials can also be managed via environment variables or IAM roles for EC2 instances.

ERROR HANDLING

Errors from aws cloudwatch commands are usually returned in JSON format, providing specific error codes and messages that can help in debugging. Common issues include insufficient permissions, incorrect parameters, or throttling.

PAGING AND PAGINATION

For commands that return a large number of results (e.g., get-log-events, describe-alarms), the AWS CLI automatically handles pagination to retrieve all results. You can control this behavior using --starting-token, --max-items, and --page-size.

HISTORY

The AWS CLI was first released in 2013, providing a unified tool to manage AWS services from the command line. The cloudwatch subcommand has evolved alongside the AWS CloudWatch service, continually adding support for new features like CloudWatch Logs, Contributor Insights, and Anomaly Detection. Its development is ongoing, with regular updates to support new CloudWatch APIs and enhancements to existing functionalities, making it a cornerstone for automation and operations within AWS environments.

SEE ALSO

aws(1), aws s3(1), aws ec2(1), jq(1)

Copied to clipboard