AWS Builder Center
Q-Bits: Simplify CloudWatch CLI commands with Q Developer

Q-Bits: Simplify CloudWatch CLI commands with Q Developer

The article discusses how the author uses Amazon Q Developer to simplify interacting with Amazon CloudWatch from the command line.

Welcome to another installment of  Q-Bits , our regular series showcasing cool ways Amazon employees are leveraging Amazon Q Developer. Today, we're diving into how Q Developer can assist with CloudWatch in the AWS CLI.
I rely heavily on  Amazon CloudWatch  to monitor the health and performance of my applications. CloudWatch provides a wealth of invaluable data, but I've always found it challenging to remember the exact syntax for querying specific metrics from the command line. That is, until I started using  Amazon Q Developer .
Q Developer has been a game-changer for me when it comes to interacting with CloudWatch. Instead of having to recall the various namespaces, metric names, and dimensions required for each CLI command, I can now simply describe what I want to do in natural language, and Q translates that into the appropriate AWS CLI syntax.
Let's start with an example from my work with  Amazon Simple Storage Service (Amazon S3) . I need to check the average size of my S3 buckets, but the full AWS CLI command to do this can be quite complex:
aws cloudwatch get-metric-statistics --metric-name BucketSizeBytes --namespace AWS/S3 --statistics Average --dimensions Name=BucketName,Value=my-bucket-name Name=StorageType,Value=StandardStorage --start-time 2024-12-01T00:00:00Z --end-time 2024-12-31T23:59:59Z --period 2592000 --region us-east-1 --output text --query 'Datapoints[0].Average'
With Q, I can simply say "Using CloudWatch, display the average size of the S3 bucket my-bucket-name during December 2024." Q takes care of translating that request into the correct CLI command, saving me time and headaches. Note that there a few ways to get this data at the command line, so I have specified that I want Q to use CloudWatch.
The same goes for querying other CloudWatch metrics. If I want to see the average hourly CPU utilization for a specific  Amazon Elastic Compute Cloud (Amazon EC2)  instance, I can say "Using CloudWatch, display the average hourly CPU utilization for instance i-0123456789abcdef on January 26, 2025." Q will handle the details of constructing the appropriate command:
aws cloudwatch get-metric-statistics --metric-name CPUUtilization --start-time 2025-01-26T00:00:00 --end-time 2025-01-26T23:59:59 --period 3600 --namespace AWS/EC2 --statistics Average --dimensions Name=InstanceId,Value=i-0123456789abcdef
This works for most any AWS service, like getting the average read IOPS for an  Amazon Aurora  cluster. I can simply say "Using CloudWatch, display the average read IOPS for the Aurora cluster named my-cluster-name on January 21, 2025," and Q will take care of the details:
aws cloudwatch get-metric-statistics --namespace AWS/RDS --metric-name ReadIOPS --dimensions Name=DBClusterIdentifier,Value=my-cluster-name --start-time 2025-01-21T00:00:00Z --end-time 2025-01-22T00:00:00Z --period 3600 --statistics Average
Beyond CloudWatch metrics, Q can also help with querying CloudWatch Logs. If I need to tail the logs for a Lambda function, I can just say "Using CloudWatch, tail the logs for the Lambda function my-function-name," and Q will translate that into the appropriate  aws logs tail  command.
After using Q for the past few years, I've found that it saves me a significant amount of time and cognitive load when working with CloudWatch. Instead of having to remember all the various service namespaces, metric names, and dimensions, I can focus on describing what I want to do in plain English, and let Q handle the technical details. This has made me much more productive and efficient in my day-to-day work with AWS services.
If you, like me, struggle to keep track of the CloudWatch CLI syntax, I highly recommend giving Amazon Q Developer a try. It's a simple but powerful tool that can help streamline your interactions with CloudWatch and other AWS services. Give it a shot, and let me know how it goes!  
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article