Created
September 15, 2018 06:34
-
-
Save Twinuma/e7490b83f3d5600486938b428b8a123b to your computer and use it in GitHub Desktop.
pecoってAWS System Manager Session ManagerでEC2にアクセスする
This file contains hidden or 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 --profile $1 --region $2\ | |
--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 --profile $1 --region $2 --query "Reservations[].Instances[?contains(Tags[].Value, \`${NAME_SSM2EC2}\`)].InstanceId[]" | sed -e 's/[]" ,\[]//g' | sed -e '/^$/d') | |
aws ssm start-session --target ${ID_SSM2EC2} --profile $1 --region $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./ssm-peco.sh demo-iam ap-northeast-1