Skip to content

Instantly share code, notes, and snippets.

@tmtk75
Last active January 28, 2016 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmtk75/cdcd7ae27ab13fc2eab7 to your computer and use it in GitHub Desktop.
Save tmtk75/cdcd7ae27ab13fc2eab7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
sort_key=${1-Name}
aws ec2 describe-instances \
--output table \
--filter Name=instance-state-name,Values=running \
Name=tag-key,Values=role \
Name=tag-key,Values=site \
--query '
sort_by(
Reservations[].Instances[],
&(Tags[?Key==`'$sort_key'`]|[0].Value)
)[]
.[
Tags[?Key==`Name`]|[0].Value,
Tags[?Key==`site`]|[0].Value,
Tags[?Key==`role`]|[0].Value,
InstanceType,
InstanceId,
PublicIpAddress,
PrivateIpAddress,
Placement.AvailabilityZone
]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment