Skip to content

Instantly share code, notes, and snippets.

@jiskanulo
Created April 13, 2020 09:26
Show Gist options
  • Save jiskanulo/8d700bacf684cb0ad31e50dbad43bc00 to your computer and use it in GitHub Desktop.
Save jiskanulo/8d700bacf684cb0ad31e50dbad43bc00 to your computer and use it in GitHub Desktop.
~/.aws/cli/alias
[toplevel]
ss =
!f() {
aws_profile=${1:-"saml"}
if [ -z "$aws_profile" ]; then
echo "you must be specified aws_profile as argument."
echo "exaple: aws ss <aws_profile>"
exit 1
fi
instance_ids=$(aws ec2 --profile ${aws_profile} --region ap-northeast-1 describe-instances --query 'Reservations[].Instances[].[InstanceId, State.Name, InstanceType, PrivateIpAddress, Platform || `Linux`, Tags[?Key == `Name`].Value | [0]]' --output text)
if [ $? -ne 0 -o -z "${instance_ids}" ]; then
echo "describe-instances failued."
exit 1
fi
instance_id=$(echo "${instance_ids}" | column -t | fzf --reverse | cut -d ' ' -f 1)
if [ -z "$instance_id" ]; then
echo "instance_id: '${instance_id}' is invalid."
exit 1
fi
echo "run: aws ssm start-session --target ${instance_id}"
aws ssm --profile ${aws_profile} --region ap-northeast-1 start-session --target ${instance_id}
}; f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment