Menu

Quick Tip: How to Easily Get CloudWatch Metrics Graph Images
📰

Quick Tip: How to Easily Get CloudWatch Metrics Graph Images

DEV Community: aws·kawasaki031677·about 9 hours ago
#QRRqIpYl
#devtoaws#devto#dev#metrics#metric
Reading 0:00
15s threshold

kawasaki031677

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

Enter fullscreen mode Exit fullscreen mode

Running this command will save the metrics image as image.png.

Generated Image Example

image (1).png

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.

image.png

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.