Remote development with Visual Studio Code and EC2
Tags: ec2, vscode, programming, tutorial
Published: 2023-01-20 07:20:31

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.

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.

![Install Remote SSH](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eq02leq0ta4ssv1ppnoy.png)

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

![Connect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vll1wvwfly0xxzf1dx37.png)

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_

![SSH configuration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l2vlm4tobw09nk001ibr.png)

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.

![SSH config](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rrqe71f2yfh8jr2gkizz.png)

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.

![SSH connect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7sarkf4pwjtafy60w2ju.png)

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

![Open remote folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dyfehbvekh54nh1fxsoe.png)

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.

{% embed https://youtu.be/elkL1OF9fxI %}

If you have any questions, comments, or feedback then please leave them below. [Subscribe to my channel](https://www.youtube.com/srcecde?sub_confirmation=1) for more.