2
2

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.

AWS Session Managerでinstance idをいちいち調べるのがだるい

Posted at

aws ssm start-session は大変に便利なんだけど instance idをいちいち調べるのがだるい
サーバの名前からpecoで選んで繋げるようにする

#!/bin/bash

# 必要なら aws ec2 commandでリストアップする 基本重いからベタ書き
target_server_name=$(peco --prompt "Select server to start-session >" << EOS
server-a
server-b
server-c
EOS
)

if [ -z "${target_server_name}" ]; then
  exit
fi

instance_id=$(aws ec2 describe-instances --filter "Name=tag:Name,Values=${target_server_name}" --query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]" --output text)

aws ssm start-session --target "$instance_id"
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?