Skip to content

Instantly share code, notes, and snippets.

@Prajithp
Forked from carlessanagustin/aws-cli-filtering.md
Created July 16, 2018 14:56
Show Gist options
  • Select an option

  • Save Prajithp/bcf71c5b8f40bbea8608401942d8506a to your computer and use it in GitHub Desktop.

Select an option

Save Prajithp/bcf71c5b8f40bbea8608401942d8506a to your computer and use it in GitHub Desktop.
Filtering AWS results

Via AWS CLI filters

(http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html)

aws ec2 describe-instances --output json --filters "Name=key-name,Values=lps-bigger-eurecat"
  • To describe all instances with a Owner tag
aws ec2 describe-instances --filters "Name=tag-key,Values=Owner"
  • To describe all instances with a Purpose=test tag
aws ec2 describe-instances --filters "Name=tag:Purpose,Values=test"

Using jq

(https://github.com/mwilliamson/jq.py)

aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.LaunchTime > "2015-01-28") | select(.State.Code != 48) | [.LaunchTime, .State.Name, (.Tags[]|select(.Key=="Name")|.Value)]'
aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.KeyName == "MyKey") | { KeyName, PublicIpAddress}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment