Building and Sharing CloudWatch Dashboards
This lesson explains how CloudWatch dashboards show metrics, alarms and log query results together so operators see the state of a workload at a glance, a frequent subject of configuration questions.
Learning outcomes
After completing this lesson, you will be able to:
- Choose widgets for a dashboard.
- Manage dashboards as code with variables.
- Share dashboards with people outside the account.
Widgets and layout
A dashboard contains widgets. Line and stacked area graphs show trends; number and gauge widgets show current values; bar and pie charts compare resources; alarm status widgets show the state of chosen alarms; Logs Insights widgets show the results of a saved query; text widgets hold Markdown such as runbook links; and custom widgets render the output of a Lambda function. A single graph can combine metrics from different Regions, and metric math expressions can be graphed directly. Dashboards are global resources: they are not tied to the Region in which you create them.
CloudWatch also provides automatic dashboards for many services and resource group dashboards that show all resources sharing a tag. These require no setup but cannot be customised beyond filtering; copy them to a custom dashboard to change them.
Which widget?
Dashboards as code and variables
A dashboard is stored as a JSON dashboard body, so it can be created with aws cloudwatch put-dashboard, the AWS::CloudWatch::Dashboard CloudFormation resource or a CDK construct. Managing dashboards as code keeps production and test dashboards identical and lets dashboards be reviewed with the rest of the infrastructure. Dashboard variables add a drop-down or input to the dashboard that substitutes a value, such as an instance ID, function name or Region, into every widget. One dashboard can then serve many identical resources instead of one dashboard per resource.
aws cloudwatch put-dashboard --dashboard-name checkout-prod --dashboard-body '{
"widgets": [
{"type": "metric", "x": 0, "y": 0, "width": 12, "height": 6, "properties": {
"title": "ALB 5XX and requests", "region": "eu-west-1", "stat": "Sum", "period": 60,
"metrics": [["AWS/ApplicationELB", "HTTPCode_Target_5XX_Count", "LoadBalancer", "app/checkout/abc123"],
[".", "RequestCount", ".", "."]]}},
{"type": "alarm", "x": 12, "y": 0, "width": 12, "height": 6, "properties": {
"title": "Checkout alarms",
"alarms": ["arn:aws:cloudwatch:eu-west-1:111122223333:alarm:checkout-5xx"]}}
]}'Sharing dashboards
Dashboards can be viewed by anyone with IAM permissions in the account. To show a dashboard to people without AWS credentials, such as business stakeholders or a support desk, CloudWatch offers dashboard sharing. A dashboard can be shared publicly with anyone who has the link, with specific email addresses (viewers sign in with a password through Amazon Cognito), or through a single sign-on provider. Sharing creates an IAM role that limits what viewers can read; viewers cannot change the dashboard. Sharing of dashboards that contain Logs Insights widgets requires the role to have logs permissions.
Sharing a dashboard
One dashboard for many functions
A team runs 40 Lambda functions with the same structure. Instead of 40 dashboards, they build one dashboard with graphs for Invocations, Errors, Duration p99 and Throttles, and add a property variable named FunctionName whose values come from a metric search of AWS/Lambda. Selecting a function in the drop-down updates every widget. A text widget at the top links to the runbook for Lambda throttling, and an alarm status widget shows the alarms whose names start with the selected function. The dashboard body is stored in the team's repository and deployed with CloudFormation.
Can one dashboard graph show metrics from several Regions?
Show answer
Yes. Dashboards are global, and a graph can combine metrics from different Regions.
Exam Tips
Remember for the exam
- Dashboards are global and can show metrics from several Regions in one graph.
- Manage dashboards as code with PutDashboard, CloudFormation or CDK.
- Dashboard variables let one dashboard serve many similar resources.
- Share dashboards with people who have no AWS account through dashboard sharing.