Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Last active August 19, 2023 13:39
Show Gist options
  • Save turboBasic/b4e893d23586f620c91fb9883c31939c to your computer and use it in GitHub Desktop.
Save turboBasic/b4e893d23586f620c91fb9883c31939c to your computer and use it in GitHub Desktop.
Helpers for AWS CLI #aws #zsh #bash
# List running EC2 instances filtered by `Name` tag
#
# params:
# $1 - optional string. Filters output by instances with `Name` tag containing the string
function ec2 {
aws ec2 describe-instances \
--filter "Name=instance-state-name,Values=running" \
--filter "Name=tag:Name,Values=*$1*" \
--query "Reservations[].Instances[].{
id: InstanceId,
name: Tags[?Key=='Name'].Value | join(' ', @)
}" \
| jq "map({(.name): .id}) | add"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment