Search code examples
amazon-web-servicesamazon-ec2amazon-cloudwatchamazon-ebs

cloudwatch command get-metric-data


I'm not able to get the metric data through this command.

aws cloudwatch get-metric-data --metric-data-queries jsonfile.json \
   --start-time 2019-02-01T10:40:0000 --end-time 2019-02-27T14:12:0000 

The following error is getting shown.

Error parsing parameter '--metric-data-queries': Expected: '=', received: 'EOF' for input:

jsonfile.json

Here, the jsonfile.json contains my query, defined below.

[
    {
        "Id": "MyRequest",
        "MetricStat": {
            "Metric": {
                "Namespace": "AWS/EBS",
                "MetricName": "VolumeReadBytes",
                "Dimensions": [
                    {
                        "Name": "VolumeId",
                        "Value": "vol-******420********"
                    }
                ]
            },
            "Period": "3600",
            "Stat": "Average",
            "Unit": "Bytes"
        },
        "Label": "myRequestLabel",
        "ReturnData": "true"
    }
]

Solution

  • I think what you need to run is;

    aws cloudwatch get-metric-data --cli-input-json file://jsonfile.json
    

    The content of your jsonfile.json should be as follows;

    {
        "MetricDataQueries": [
            {
                "Id": "myRequest",
                "MetricStat": {
                    "Metric": {
                        "Namespace": "AWS/EBS",
                        "MetricName": "VolumeReadBytes",
                        "Dimensions": [
                            {
                                "Name": "VolumeId",
                                "Value": "vol-******420******"
                            }
                        ]
                    },
                    "Period": 3600,
                    "Stat": "Average",
                    "Unit": "Bytes"
                },
                "Label": "myRequestLabel",
                "ReturnData": true
            }
        ],
        "StartTime": "2019-02-01T10:40:0000",
        "EndTime": "2019-02-27T14:12:0000"
    }