Created
September 17, 2021 11:39
-
-
Save mijndert/708fcf8cc2cf2ea0f53b70db833db89f 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 | |
green=`tput setaf 2` | |
reset=`tput sgr0` | |
echo "${green}Hostname of the resource you want to connect to:${reset}" | |
read -e hostname | |
echo "${green}Port of the thing you want to connect to:${reset}" | |
read -e port | |
echo "${green}Connecting (quit with ctrl+c)${reset}" | |
export ID=$(aws ec2 describe-instances --output=text --query "Reservations[*].Instances[*].InstanceId" --filters Name=tag:Name,Values="BastionStack*") | |
export AZ=$(aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].[Placement.AvailabilityZone]' --filters Name=tag:Name,Values="BastionStack*") | |
aws ec2-instance-connect \ | |
send-ssh-public-key \ | |
--availability-zone $AZ \ | |
--instance-id $ID \ | |
--instance-os-user ssm-user \ | |
--ssh-public-key file://$HOME/.ssh/id_rsa.pub &>/dev/null & disown; | |
ssh ssm-user@$ID -NL $port\:$hostname\:$port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment