Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k 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 (44.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/ 

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories

...