Skip to content

Instantly share code, notes, and snippets.

@shirou
Last active October 21, 2020 05:21
Show Gist options
  • Save shirou/b9dd10e5e0772a68406510495a6a6e17 to your computer and use it in GitHub Desktop.
Save shirou/b9dd10e5e0772a68406510495a6a6e17 to your computer and use it in GitHub Desktop.
connect instance via ssm selecting with peco
#!/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