Introduction
When you need to get CloudWatch metrics graph images, the AWS CLI's get-metric-widget-image command is very convenient.
Example
~ $ aws cloudwatch get-metric-widget-image \
--metric-widget '{
"view": "timeSeries",
"stacked": false,
"metrics": [
[ "AWS/S3", "BucketSizeBytes", "BucketName", "xxx", "StorageType", "StandardStorage", { "period": 86400, "id": "m1" } ]
],
"width": 1742,
"height": 260,
"start": "-PT336H",
"end": "P0D"
}' \
--output-format png \
--output text | base64 --decode > image.png
Running this command will save the metrics image as image.png.
Generated Image Example
How to Check the metric-widget JSON
You can verify the target metrics' JSON configuration by clicking on the "Source" tab when viewing the graph.
This JSON can be used directly as a command argument.
Summary
While it might seem like a minor tip, it's actually quite useful! Try automating it with the CLI instead of manually taking screenshots.


Top comments (0)