You could use the GetMetricWidgetImage API or get-metric-widget-image command to achieve that.
An example get-metric-widget-image
command line:
aws cloudwatch get-metric-widget-image --metric-widget '
{
"metrics": [
[ { "expression": "AVG(METRICS())", "label": "Average Access Speed", "id": "e1", "region": "eu-central-1" } ],
[ "...", "www.xyz.ee", { "label": "[avg: ${AVG}] www.xyz.ee", "id": "m2", "visible": false } ],
[ "...", "www.abc.com", { "label": "[avg: ${AVG}] www.abc.com", "id": "m3", "visible": false } ],
],
"view": "timeSeries",
"stacked": false,
"region": "eu-central-1",
"title": "Response Time",
"period": 300,
"stat": "Average"
}
' | jq -r .MetricWidgetImage | base64 -d | display
In order to get the metric-widget source, it is the easiest to go the cloudwatch dashboard, select the widget for editing, and select the "Source" tab. There you can copy the source code and use it in the above command line.
There is an also a thread about how to use the command: How to use aws cloudwatch get-metric-widget-image?