Skip to content

Instantly share code, notes, and snippets.

@lunarxlark
Last active April 8, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunarxlark/caf962ba39685d48140f87085fc48186 to your computer and use it in GitHub Desktop.
Save lunarxlark/caf962ba39685d48140f87085fc48186 to your computer and use it in GitHub Desktop.
pecoってAWS System Manager Session ManagerでEC2にアクセスする ref: https://qiita.com/lunarxlark/items/8983b7650f277b71ffba
#!/bin/bash
# Tags.Name取得
export NAME_SSM2EC2=$(aws ec2 describe-instances \
--query "Reservations[].Instances[].Tags[?contains(Key, \`Name\`)].Value[]" | \
sed -e 's/[]" ,\[]//g' | \
sed -e "/^$/d" | peco)
# instance-id取得
export ID_SSM2EC2=$(aws ec2 describe-instances --query "Reservations[].Instances[?contains(Tags[].Value, \`${NAME_SSM2EC2}\`)].InstanceId[]" | sed -e 's/[]" ,\[]//g' | sed -e '/^$/d')
aws ssm start-session --target ${ID_SSM2EC2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment