Sampath
Sampath

Reputation: 71

How to query nested value in AWS Cli?

"MetricAlarms": [
    {
        "AlarmName": "AWS_CPUUtilisation_Alarm",
        "MetricName": "CPUUtilization",
        "Namespace": "AWS/EC2",
        "Statistic": "Average",
        "Dimensions": [
            {
                "Name": "InstanceId",
                "Value": "i-XXXXXXXXX"
            }
        ],
        "Period": 300,
        "EvaluationPeriods": 1,
    },

From the above data how can i get only instance id by using below command I am getting name and value:

aws cloudwatch describe-alarms --query "MetricAlarms[*].{Instanceid:Dimensions}" --output table

Upvotes: 2

Views: 469

Answers (1)

Paolo
Paolo

Reputation: 26074

You're almost there:

aws cloudwatch describe-alarms --query "MetricAlarms[*].{Instanceid:Dimensions}[*].Instanceid[*].Value"

You might find it useful to play around with a tool like jmespath terminal or jmespath tutorial.

Upvotes: 3

Related Questions