Last active
August 30, 2024 20:18
-
-
Save nukosuke/b4507f41f934e8897870934a46814de3 to your computer and use it in GitHub Desktop.
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 | |
# 使いかた | |
# source ec2ssh.bash | |
# ec2ssh | |
# | |
# インストール方法 | |
# echo "[ -f ~/ec2ssh.bash ] && source ~/ec2ssh.bash" >> ~/.bashrc | |
# | |
# 依存 | |
# aws-cli - https://github.com/aws/aws-cli | |
# fzf - https://github.com/junegunn/fzf?tab=readme-ov-file#using-git | |
INSTANCE_FILE="$HOME/ec2_instances.txt" | |
function _fetch_ec2_instance_list() { | |
aws ec2 describe-instances \ | |
--output text \ | |
--query "Reservations[].Instances[].{InstanceId:InstanceId,KeyName:KeyName} | sort_by(@, &KeyName)" \ | |
> $INSTANCE_FILE | |
} | |
function _ec2ssh() { | |
_fetch_ec2_instance_list | |
local instance_id=$(cat $INSTANCE_FILE \ | |
| fzf -1 --layout reverse \ | |
| cut -f1) | |
aws ssm start-session --target $instance_id | |
} | |
alias ec2ssh=_ec2ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
インストール方法