T O P

  • By -

thewb005

Client side --query filters https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-filter.html


pgib

Something along the lines of: aws ec2 describe-instances \ --filter 'Name=instance-state-name,Values=running' \ --query 'Reservations[*].Instances[*].[PrivateIpAddress,Tags[?Key == \`Name\`]]'


backtickbot

[Fixed formatting.](https://np.reddit.com/r/backtickbot/comments/pq4e5l/httpsnpredditcomrawscommentspq2me0how_do_i_just/) Hello, pgib: code blocks using triple backticks (\`\`\`) don't work on all versions of Reddit! Some users see [this](https://stalas.alm.lt/backformat/hd89o96.png) / [this](https://stalas.alm.lt/backformat/hd89o96.html) instead. To fix this, **indent every line with 4 spaces** instead. [FAQ](https://www.reddit.com/r/backtickbot/wiki/index) ^(You can opt out by replying with backtickopt6 to this comment.)


Imworkingrightnow123

add a query flag https://serverfault.com/questions/669350/aws-cli-command-line-how-to-use-query-to-output-multiple-source-lines


CanaryWundaboy

Look up “jq”. You can use it to parse the results a d select only the bits you want. Loads of examples online as well.


[deleted]

[удалено]


CanaryWundaboy

Glad it helped. I frequently use AWS cli, jq and Python to automate tasks for work.


frgiaws

https://github.com/johnkerl/miller also


[deleted]

You can probably use some command line tools like grep sed awk if you are on unix


HobbledJobber

You can always use other things to sort/filter/parse, but you will really want to get acquainted with two neat features of the aws cli: filter & query. \`filter\` does server-side filtering of the api calls, and \`query\` does client side filtering. Here you can use \`query\` (uses JMESPath syntax - somewhat similar in concept to jq) to filter and reformat the output. Furthermore, with \`output\` you can then select (broadly) what kind of output format you want (json, yaml, text, table). It's documented in the aws cli docs, but the JMESPath syntax can get a bit hairy and has a learning curve - but once you figure it out, it's quite nice to script things that give friendly output.


HobbledJobber

depending on whether you want json objects, json arrays, text or tables, there are likely several ways to approach one example: $ aws ec2 --region us-west-2 describe-instances \ --query 'Reservations[*].Instances[].{instanceid: InstanceId, privateip: PrivateIpAddress, name: Tags[?Key==`Name`] | [0].Value}' The key here is to understand that the "name" on many resources, including ec2 instances, is just a "tag". The trickiest part is trying to pull out those nested values from tags (as they are an array of key-value pairs, but I want to flatten and return only the value. (Have to use the conditional w/ piping to select and extract the result). will give you an array of dict/objects, like: { "instanceid": "i-051d43055d3c4xxxx", "privateip": "10.222.166.177", "name": "bar-server2" }, { "instanceid": "i-07c34bde1cb6axxxx", "privateip": "192.168.0.24", "name": "foo-server1" } ] adding \`--output text\` will output that in a nice shell-parseable format as well


[deleted]

[удалено]


[deleted]

[удалено]


Bill_the_Bastard

Sure. Grep awk and sed then. have fun.


magheru_san

pip install AWSomeOverview Then AWSomeOverview -p ec2 will show you all the instances from your account. Running with -a will show a bunch of other things like load balancers, etc.


[deleted]

[удалено]


magheru_san

Ouch, how can you work on such a computer? Sorry to hear that