Last active
April 8, 2019 16:29
-
-
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
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 | |
# 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