Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Last active May 20, 2025 10:39
Show Gist options
  • Save turboBasic/02cf7612109d6d1434364bb7bf2d3ac6 to your computer and use it in GitHub Desktop.
Save turboBasic/02cf7612109d6d1434364bb7bf2d3ac6 to your computer and use it in GitHub Desktop.
Helpers for AWS CLI #aws #zsh
# List running EC2 instances filtered by `Name` tag
#
# params:
# $1 - optional string. Filters output by instances with `Name` tag containing the string
function aws-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