Skip to content

Instantly share code, notes, and snippets.

@lgs
Forked from lmammino/README.md
Created March 19, 2024 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgs/a4115cd4f9a30ebac24148fb5228ddcf to your computer and use it in GitHub Desktop.
Save lgs/a4115cd4f9a30ebac24148fb5228ddcf to your computer and use it in GitHub Desktop.
Setup SSM to connect your VSCode to a remote Cloud9 Instance (awsbites.com)

Initial steps

  1. Launch Cloud9 IDE with SSM option
  2. When it launchers, open the Cloud9 IDE in the AWS Console

With SSM

Install:

  • AWS CLI
  • Session Manager plugin for AWS CLI installed

Then follow these steps:

  1. On your client, generate (or use an existing) SSH key.

ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_c9

  1. On Cloud9, get your instance ID, e.g., curl [http://169.254.169.254/latest/meta-data/instance-id](http://169.254.169.254/latest/meta-data/instance-id)
  2. Add the public key to the authorized keys on the Cloud9 instance (~/.ssh/authorized_keys)
  3. On your client machine, edit ~/.ssh/config, adding:
Host i-* mi-*
    ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
  1. Check that you can log in to your Cloud9 instance with the SSH client:
ssh -i ~/.ssh/id_rsa_c9 ec2-user@i-0ec1bd46c62784cff
  1. Create an entry in your .ssh/config (Note the AWS_PROFILE setting so you have credentials!)
Host i-0ec1bd46c62784cff
    HostName i-0ec1bd46c62784cff
    IdentityFile ~/.ssh/id_rsa_c9
    User ec2-user
    ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
  1. Finally, Connect to the host - Cmd+Shift+PConnect to Host...

Now you’re coding! 😍

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