VSCode Remote Development with AWS SSM

If you are like me, you find yourself working on projects in VSCode, committing your branch, and deploying these changes to a dev environment. Recently my company disabled any form of public SSH access, and this made remote development a lot harder.

We set up Session Manager in AWS and this filled the gap of needing SSH access to the server, but we still had the issue of not being about to connect for remote development. I did some searching on the web and found helpful information for achieving this.

This assumes that you already have a public key that is authorized on the server, if you don't have one there is a large number of guides out there that instruct you on doing this. It is also assumed this is being done from a Windows machine.

Getting Connect

The first then we need to do is update our SSH config and add two items to this. First, we need to add the ProxyCommand config. This will proxy the sessions for hosts matching the hostname through AWS SSM.

host i-* mi-*
  ProxyCommand C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=22"

Next, we need to add the following right below this. Make sure to update the <ec2 id> section with your corresponding Id, and correct the IdentityFile path to match your own location.

Host <ec2 id>
  HostName <ec2 id>
  User ubuntu
  IdentityFile ~/.ssh/id_rsa.pub

Once you have this setup, you can connect to the remote host by pressing CTRL+Shift+P on your Windows computer, searching for Remote-SSH: Connect to Host... and then selecting your Id from the list. From this point, VSCode works just like it would with any other remote development connection.

Nathanial Wilson

Nathanial Wilson