Is it possible to create graphs programmatically in a Cloudwatch dashboard using the AWS API or a SDK?
Edit I'd like to use the API to create Metric and Text widgets in the Cloudwatch Dashboard. I do not want to manually create each graph.
If your use case doesn't support the use of the CloudWatch unified agent, you can use the PutMetricData API to push custom metrics to CloudWatch.
To see the visualization, run your query. Then choose the Visualization tab, select the arrow next to Line, and choose Bar. Visualizations are limited to up to 100 bars in the bar chart. For a complete tutorial, see Tutorial: Run a query that produces a visualization grouped by log fields.
As of 05 Jul 2017 it is possible: https://aws.amazon.com/blogs/aws/new-api-cloudformation-support-for-amazon-cloudwatch-dashboards/
This answer is now out of date, please see the other answer about using CloudFormation to codify CloudWatch Dashboards. For historical purposes here is my original reply: The accepted answer is effectively "no". However it may be worth noting that if you were to create a graph through the web interface and inspect the URL that is generated for you through the "Copy URL" button, you can see the patterns it uses and you could come up with your own URL. Note that when you click the "Copy URL" button in the CloudWatch web interface, it doesn't do anything special on its backend other than programmatically generate a URL for you based on your currently selected options. Therefore in a way this offers you a way to generate your own graphs programmatically, albeit in a rather unintuitive and messy way since as far as I can tell there isn't a published specification for how those URLs are assembled and you must figure it out on your own through trial and error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With