Srce Cde
Published in

Srce Cde

Remote development with Visual Studio Code and EC2

Today, we generally need to do remote development every now and then for different reasons. Let’s try to understand the need for remote development with an example and is not limited to this. For instance, if you are working on a big data engineering project or data science project where you need compute/memory optimized hardware and GPUs respectively. In most cases, with this kind of hardware, the configuration will not be available as a part of your local system. Hence, you have to go for cloud computing or any on-premise server/VM setups within the organization. However, in both scenarios, you will take remote access to the VMs for development.

Photo by Austin Distel on Unsplash

As a part of this article, we will consider Amazon EC2 as our VM for development. Assuming, you launched an EC2 instance with Linux or Ubuntu to enable an operating system for remote development. Here, there is no UI or IDE setup for development and using text editors like vim, nano for project development is not feasible.

To solve this problem, we can connect the IDE (VS Code) from your local machine to the remote instance (VM) for development via SSH on port 22. Let’s do this hands-on.

Pre-requisite

  • Install Visual Studio Code
  • Launch the EC2 instance
  • PEM file to SSH into the EC2 instance

Hands-on

As a next step, launch VS Code & go to Extensions and search ssh. Select the extension as shown below and install it.

.Post installation, click on the green icon (Open a Remote Window) on the bottom-left corner.

After clicking on the above icon, the pop-up will appear. Click on Open SSH Configuration File and select the file where you want to configure the remote host (EC2). In my case, I will select /Users/username/.ssh/config

In this file, add the hosts with which you would like to connect for remote development in the below format.

Host alias-name    
Hostname name-of-host/IPv4-address
User remote-username
IdentityFile path-of-the-pem-file

Multiple hosts can be added here as shown below.

Save the config file. As a next step, click on the green icon (bottom-left corner) & choose Connect to Host. This will list the alias-name of the hosts which are added as a part of the configuration. So, select the host with which you want to connect & it will open a new window. It will take a while to connect.

As soon as it is connected, you will be able to see the alias name in the bottom-left corner.

As a next step, you can open the directory from the remote machine, execute the commands, set the machine for development, and so on.

This is how we can do the remote development from the local IDE on the remote host.

For a detailed step-by-step tutorial and its implementation please refer to the below video.

If you have any questions, comments, or feedback then please leave them below. Subscribe to my channel for more.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store