0 votes
1 view
in AWS by (18.2k points)

I have this command:

aws ec2 describe-regions --output=json

the output looks like:

{

    "Regions": [

        {

            "Endpoint": "ec2.eu-north-1.amazonaws.com", 

            "RegionName": "eu-north-1"

        }, 

        {

            "Endpoint": "ec2.ap-northeast-2.amazonaws.com", 

            "RegionName": "ap-northeast-2"

        }, 

        {

            "Endpoint": "ec2.us-west-2.amazonaws.com", 

            "RegionName": "us-west-2"

        }

    ]

}

that's not really usable by machine though, I am looking for output on a single-line like so:

{"Regions":[{"Endpoint":"ec2.eu-north-1.amazonaws.com","RegionName":"eu-north-1"},{"Endpoint":"ec2.ap-northeast-2.amazonaws.com","RegionName":"ap-northeast-2"},{"Endpoint":"ec2.us-west-2.amazonaws.com","RegionName":"us-west-2"}]}

is there some command with the aws-cli that gives me machine-readable JSON? Something like:

aws ec2 describe-regions --output='json-for-machines'

?

1 Answer

0 votes
by (42.4k points)

Use jq to compact it like so.

aws ec2 describe-regions --output=json| jq -c

output becomes

{"Regions":[{"Endpoint":"ec2.eu-north-1.amazonaws.com","RegionName":"eu-north-1"},{"Endpoint":"ec2.ap-northeast-2.amazonaws.com","RegionName":"ap-northeast-2"},{"Endpoint":"ec2.us-west-2.amazonaws.com","RegionName":"us-west-2"}]}

https://stedolan.github.io/jq/ 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...