1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

TagからEC2-IDを取得してSSMログインするときの覚書

Posted at

(ssmでなんやかんやする時にecsのIDを知りたい)

tagを指定してfiltersで取得する覚書
{} 内は適宜置き換えてください。

export ENV={env}
export AWS_DEFAULT_REGION=ap-northeast-1

export BASION_ID=`aws ec2 describe-instances --filters "Name=tag:{tag-key},Values=$ENV" | jq -r .Reservations[0].Instances[0].InstanceId`

これ↓でssmでログインできるはず

aws ssm start-session --target $BASION_ID

sshしたい場合は↓を ~/.ssh/config に追記

host i-* mi-*
    ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"

これ↓でsshでログインできるはず

ssh -i id_rsa ec2-user@$BASION_ID

※ 鍵の設定は必要
※ 22番ポートは開けなくてよい


RDSトンネルしたい場合

ssh -i id_rsa ec2-user@$BASION_ID -L {your-tunnel-port}:{your-rds-host}:{your-rds-port}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?