aws cli and jq filtering

Long time no see huh? ;)

I’m diving into Amazon Web Services for some months now, and I must say I’m pretty impressed by the overall quality. Compared to the other “clouds” I’ve played with, it’s the most mature and comprehensive by far.

While writing a couple of tools to make my life easier, there’s one piece that took me longer: filtering the output of the aws ec2 describe-instances command. The output is in JSON, which is quite nice you might say, and it is, but when it comes to interact with JSON in the command line, things can get a little messy.

There’s a fantastic tool around to ease the process, its name is jq. While its basic usage is pretty straightforward, things are way more complicated to order and filter datas coming out from the aws command line.

Here are a couple of examples that I would have loved someone had written before me:

That command will output the full instances list and their properties.

This will output your instances id list in a raw (-r) format

Now what about listing your instances ids, followed by the names you gave in the tag property? Sounds easy right? well let’s see:

Yeaah, right, now you get what I meant. You might want to crawl jq’s official documentation, but honestly it served me very little in comparison of this fantastic post written by a guy with much more patience than I have :)

Hope this helps!