Skip to content

Instantly share code, notes, and snippets.

@davehewy
Last active March 15, 2021 11:37
Show Gist options
  • Save davehewy/ccb680810db1cf055a192a736545ce09 to your computer and use it in GitHub Desktop.
Save davehewy/ccb680810db1cf055a192a736545ce09 to your computer and use it in GitHub Desktop.
#!/bin/bash
INSTANCE_PLACEMENT=$(aws ec2 describe-instances --instance-id ${1} | jq -r ".Reservations[] .Instances[].Placement.AvailabilityZone")
AZ=$(echo ${INSTANCE_PLACEMENT} | awk '{ print substr($1, length($1)) }')
REGION=$(echo ${INSTANCE_PLACEMENT} | awk '{ print substr($1, 0, length($1)-1) }')
aws ec2-instance-connect send-ssh-public-key --instance-id ${1} --availability-zone ${REGION}${AZ} --instance-os-user ec2-user --ssh-public-key file:///Users/your_user/.ssh/id_rsa.pub
aws ssm start-session --target ${1} --document-name AWS-StartSSHSession --parameters portNumber=${2}
@davehewy
Copy link
Author

Host i-*
    user ec2-user
    ProxyCommand ~/.ssh/example.sh %h %p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment