Created
June 1, 2021 11:40
-
-
Save mijndert/6ea3edc80300a6185dfee88111e46b0c to your computer and use it in GitHub Desktop.
Revisions
-
mijndert created this gist
Jun 1, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ #!/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