0
0
AWScloud~5 mins

CloudWatch dashboards in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
CloudWatch dashboards help you see important information about your cloud resources in one place. They show graphs and numbers that update automatically so you can watch how your apps and servers are doing.
When you want to track how much CPU your servers are using over time.
When you need to see if your website is getting more visitors or less.
When you want to watch error rates in your app to catch problems early.
When you want to combine data from different services into one view.
When you want to share system status with your team easily.
Config File - dashboard.json
dashboard.json
{
  "widgets": [
    {
      "type": "metric",
      "x": 0,
      "y": 0,
      "width": 12,
      "height": 6,
      "properties": {
        "metrics": [
          ["AWS/EC2", "CPUUtilization", "InstanceId", "i-0123456789abcdef0"]
        ],
        "period": 300,
        "stat": "Average",
        "region": "us-east-1",
        "title": "EC2 CPU Utilization"
      }
    }
  ]
}

This JSON file defines a CloudWatch dashboard with one widget.

  • widgets: The list of visual blocks on the dashboard.
  • type: The widget type, here a metric graph.
  • metrics: The data shown, here CPU use of one EC2 instance.
  • period: How often data points update, in seconds.
  • stat: The statistic shown, average CPU use.
  • region: AWS region of the data.
  • title: The widget's label on the dashboard.
Commands
This command creates or updates a CloudWatch dashboard named 'MyDashboard' using the JSON file. It sets up the dashboard with the widgets defined in the file.
Terminal
aws cloudwatch put-dashboard --dashboard-name MyDashboard --dashboard-body file://dashboard.json
Expected OutputExpected
{"DashboardValidationMessages":[]}
--dashboard-name - Specifies the name of the dashboard to create or update.
--dashboard-body - Provides the JSON content of the dashboard from a file.
This command retrieves the details of the dashboard named 'MyDashboard' so you can verify it was created correctly.
Terminal
aws cloudwatch get-dashboard --dashboard-name MyDashboard
Expected OutputExpected
{"DashboardName":"MyDashboard","DashboardArn":"arn:aws:cloudwatch::123456789012:dashboard/MyDashboard","DashboardBody":"{\"widgets\":[{\"type\":\"metric\",\"x\":0,\"y\":0,\"width\":12,\"height\":6,\"properties\":{\"metrics\":[[\"AWS/EC2\",\"CPUUtilization\",\"InstanceId\",\"i-0123456789abcdef0\"]],\"period\":300,\"stat\":\"Average\",\"region\":\"us-east-1\",\"title\":\"EC2 CPU Utilization\"}}]}"}
--dashboard-name - Specifies the dashboard to retrieve.
This command lists all CloudWatch dashboards in your account so you can see your dashboard among them.
Terminal
aws cloudwatch list-dashboards
Expected OutputExpected
{"DashboardEntries":[{"DashboardName":"MyDashboard","DashboardArn":"arn:aws:cloudwatch::123456789012:dashboard/MyDashboard"}]}
Key Concept

If you remember nothing else from this pattern, remember: CloudWatch dashboards let you see important cloud data in one place with easy-to-understand graphs.

Common Mistakes
Using incorrect JSON format in the dashboard file.
CloudWatch rejects dashboards with invalid JSON, so the dashboard won't be created.
Validate your JSON file with a JSON linter before running the put-dashboard command.
Not specifying the correct AWS region for metrics.
Metrics from the wrong region won't show up, making the dashboard empty or misleading.
Always set the 'region' field in the widget properties to the region where your resources run.
Using the wrong instance ID or metric name.
The dashboard will show no data if the metric or resource does not exist.
Double-check resource IDs and metric names before adding them to the dashboard JSON.
Summary
Create a dashboard JSON file defining widgets and metrics to display.
Use 'aws cloudwatch put-dashboard' to create or update the dashboard with your JSON file.
Verify the dashboard creation with 'aws cloudwatch get-dashboard' and list dashboards with 'aws cloudwatch list-dashboards'.