Last active
October 21, 2020 05:21
-
-
Save shirou/b9dd10e5e0772a68406510495a6a6e17 to your computer and use it in GitHub Desktop.
connect instance via ssm selecting with peco
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
#!/bin/bash | |
# fetch Inventory from SSM | |
INVENTORY=$(aws ssm get-inventory --output json | jq -r '.Entities[].Id' ) | |
# select with Tag.Name by peco | |
EC2=$(aws ec2 describe-instances --instance-ids $INVENTORY --output json --query 'Reservations[].Instances[*].{Id:InstanceId,Name:Tags[?Key==`Name`].Value}' | jq -r '.[][0] | (.Id) + " " + (.Name[0])' | peco) | |
# parse instance-id | |
INSTANCE_ID=$(echo ${EC2} | cut -f 1 -d " ") | |
aws ssm start-session --target ${INSTANCE_ID} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment