Last active
August 19, 2023 13:39
-
-
Save turboBasic/b4e893d23586f620c91fb9883c31939c to your computer and use it in GitHub Desktop.
Helpers for AWS CLI #aws #zsh #bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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