Skip to content

Instantly share code, notes, and snippets.

@Twinuma
Created September 15, 2018 06:34
Show Gist options
  • Save Twinuma/e7490b83f3d5600486938b428b8a123b to your computer and use it in GitHub Desktop.
Save Twinuma/e7490b83f3d5600486938b428b8a123b to your computer and use it in GitHub Desktop.
pecoってAWS System Manager Session ManagerでEC2にアクセスする
#!/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
@Twinuma
Copy link
Author

Twinuma commented Sep 15, 2018

./ssm-peco.sh demo-iam ap-northeast-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment