Skip to content

Instantly share code, notes, and snippets.

@jamescarr
Created April 1, 2016 12:00
Show Gist options
  • Select an option

  • Save jamescarr/f4a58b4e359a9caff8ffe199a4151fd2 to your computer and use it in GitHub Desktop.

Select an option

Save jamescarr/f4a58b4e359a9caff8ffe199a4151fd2 to your computer and use it in GitHub Desktop.
function aws-instances-describe() {
zparseopts -D -E -A opts -- o: t: s:
output=${opts[-o]:-"table"}
tag_name=${opts[-t]:-"Name"}
state=${opts[-s]:-"running"}
name=${1}
query=(
"Reservations[].Instances[]"
".{"
"Name : Tags[?Key == \`Name\`].Value | [0],"
"State : State.Name,"
"LaunchTime : LaunchTime,"
"InstanceId : InstanceId,"
"PrivateIpAddress : PrivateIpAddress,"
"PublicIpAddress : PublicIpAddress,"
"ImageId : ImageId,"
"InstanceType : InstanceType"
"}"
)
aws --output ${output} \
ec2 describe-instances \
--filters "Name=tag:${tag_name},Values=*${name}*" "Name=instance-state-name,Values=${state}" \
--query "${query}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment