Search code examples
amazon-web-servicesaws-sdkaws-cliamazon-elb

AWS CLI Describe Target Groups


haii, i have the awscli result describing the target group as json format

{
"TargetHealthDescriptions": [
    {
        "Target": {
            "Id": "1.1.1.1",
            "Port": 123,
            "AvailabilityZone": "ap-south-1"
        },
        "HealthCheckPort": "123",
        "TargetHealth": {
            "State": "healthy"
        }
    },
    {
        "Target": {
            "Id": "2.2.2.2",
            "Port": 123,
            "AvailabilityZone": "ap-south-1"
        },
        "HealthCheckPort": "123",
        "TargetHealth": {
            "State": "healthy"
        }
    }
]

}

Im trying to make an awscli script to get a result like this

[
{
    "Id": "1.1.1.1",
    "Port": 123,
    "Health": null
},
{
    "Id": "2.2.2.2",
    "Port": 123,
    "Health": null
}

]

I've tried several query methods but I have problems getting a null value for health, its any errors in the query ?

ex query

--query 'TargetHealthDescriptions[*].Target.{Id:Id, Port:Port, Health:TargetHealth.{state:State}}' --output json

Solution

  • Try the below:

    --query 'TargetHealthDescriptions[*].{Id:Target.Id,Port:Target.Port,Health:TargetHealth.State}'