DEV Community

Chirag (Srce Cde) for AWS Community Builders

Posted on • Edited on • Originally published at srcecde.me

3

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.

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

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

Connect

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

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
Enter fullscreen mode Exit fullscreen mode

Multiple hosts can be added here as shown below.

SSH config

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

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

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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay