Set Up a Remote Development Environment on an AWS Server with VSCode

Summary

This course is about setting up a remote development environments (also known as "remote interpreters") so you can code locally but execute your code on a remote server.

Remote development environments have several great advantages:

In this video we show how to create a server instance on AWS EC2, and then set up the remote development environment in VSCode.

Here is the structure of the course:

Transcript

Hello, this is Julien Salinas from NLP Cloud.

Today, I'm going to show you how to set up a remote development environment in order for you to code on your local machine, but execute your code on a remote AWS server.

There is no prerequisite for this course, so here we go.

What do we mean by remote development environment? It means actually that we are going to code locally in VS Code, as most of us today.

If you are using another development environment, you should check whether remote interpreters or remote development environments are supported or not, and we are going to actually execute the code remotely on an AWS instance.

We are choosing AWS today because I know that most of you are actually using AWS in your day-to-day production workflow, but if you are using GCP or Azure or OVH or Scaleware or anything else, the process will be very similar.

As you will see, it will be about provisioning an instance, retrieving the IP address and using it locally in VS Code to connect through SSH to the instance.

Why are we actually using remote development environment? The first reason is that we want to be able to decrease the cost of our local development environment.

You might not want to purchase a very pricey high-end MacBook Pro Ultra M2, things like this, for example, and in that case, it might be more cost-effective for you to purchase a lower-end local machine, but execute your code remotely whenever you need.

A second very important reason, especially for machine learning engineers, is that you will sometimes need to access high-end hardware like GPUs, for example, and this hardware is not necessarily available on your local machine.

For example, if you want to have access to an A100 NVIDIA GPU or H100, for sure you won't be able to get access to such GPUs locally.

Doing this, as we are going to show today, is very useful because otherwise you simply cannot get access to specific machines for GPU development.

Last of all, the fact that you are going to use a remote environment is great because it is actually a perfectly isolated environment, meaning that if you want to install specific libraries or frameworks or drivers, you can do it on your remote AWS machine.

And if tomorrow you need to install, let's say, another version of your NVIDIA drivers and CUDA toolkit or Python libraries, things like this, you simply have to provision a second server and you are perfectly sure that both servers are not going to interfere.

Both configurations are going to be perfectly isolated.

So you can also, of course, achieve similar things with Docker or even with virtual environments in Python, for example.

But imagine that you want to install several versions of your NVIDIA drivers.

This is going to be much more complex.

And in that case, provisioning several remote environments might be the only solution for you.

So the first thing that we're going to do now is actually connect to our AWS console and create a basic AWS instance, a CPU instance, and then we will use it locally from VS Code.

Here we go.

I am now on my AWS console.

If this is the first time you are using AWS, you simply need to create an account with email password.

I don't think they are asking for too much information.

And now you can create an instance in EC2.

We are going to click launch instance.

We can give a name to our instance.

So let's call it, for example, dev environment.

Okay.

Now the important part.

We need to choose an operating system for our instance.

You really want to choose Linux and as far as I'm concerned, I really like Ubuntu because it is standard and I'm sure that the most recent drivers are going to be installed on Ubuntu, especially with NVIDIA drivers, it can really help.

So I'm clicking Ubuntu here.

If this is your first time using Linux, no worries.

We are not going to need too many Linux tricks or commands.

We are going basically to do everything from VS code, except that of course behind the hood is going to be Linux, but I don't think it will be too much of a problem for you.

You can leave the 2204 LTS version as is.

And now we are going to select a simple CPU instance.

For example, on AWS, you have the M5 instance, M5 large, two CPUs, eight gigs of memory.

Perfect for us.

Maybe even too much for today, but in the future, you will have to select the instance that is perfectly fitting your needs.

Okay.

Now we need to use an SSH key pair.

So if this is the first time that you are using SSH here, you will need to create your own key pair on AWS, create new key pair.

Let's call it test key pair.

You can select the PEM format, create key pair.

And now I'm downloading it, sorry, on my machine.

Okay.

You don't need to change the security group here.

By default, the SSH port is going to be open, which is okay.

That's what we need.

Eight gigs of SSD is perfect for today.

And we can click launch instance.

Okay.

The instance is ready now.

If this is your first instance creation on AWS, maybe you will need to ask AWS support to upgrade your quota.

I'm not exactly sure.

For very pricey instances, like GPU instances, you have to ask for a quota upgrade.

For simple M5 instance, I'm not sure.

But if you're getting an error here, asking for quota increase, that's what you are going to do.

Here is our instance.

As you can see, it's already running.

It was very fast.

M5 large.

And here on the right, we have the IP address that we are going to use.

Now that we have our instance created and our SSH key pair downloaded on our machine, what we have to do is open VS Code and create the SSH connection to our remote server.

If this is the first time you are using an SSH client on Windows, you will need to activate it.

Here is a tutorial from the Windows team about how to do it.

You can simply type create SSH client on Windows, on Google, and you will find a lot of tutorials.

Here is the official one.

If you browse down a bit, it is very simple.

You simply need to activate something in the Windows applications.

If you are on Linux, it is installed by default.

So I'm now in VS Code.

At the bottom left, you can see this button here.

I'm clicking connect current window to host.

If this is the first time that you are using this remote connection module, maybe VS Code is going to download the plugin.

So it might take a couple of seconds before you can access the feature.

I'm configuring the hosts, clicking configure the hosts.

I'm on Windows today, so here is where my config is located.

And here, this is the configuration file I need to fill.

So most importantly, we need to retrieve the IP address of our instance and paste it here.

Perfect.

We can give a name to our connection, but it's only for us.

Let's call it DevHouse.

The username is the username used for the SSH client to connect to the instance.

Given that we provisioned Ubuntu server, the username is Ubuntu by default.

And when I downloaded the key pair, SSH key pair, I put it on my desktop on Windows.

So this is where VS Code is going to retrieve the key.

You can save the file and now click at the bottom, connect current window to host again.

DevHouse is what we just created.

You will need to wait here.

Very good.

You can see that VS Code is asking me for a key exchange.

So yes, this is the first time we are connecting to this instance.

So for security reasons, we need to accept this new fingerprint.

Good.

It doesn't seem very dramatic, but here we are now actually on our remote AWS instance.

And you can see it because at the bottom left, you can see SSH.

In order to check it, you can open a terminal at the top, click new terminal.

And here you can see that this terminal is absolutely not the terminal of my local Windows machine.

I am on a Ubuntu machine.

And if I want to, I can use some Linux commands as usual on Linux, like list directories.

We have nothing here, so we can create a directory.

Let's say we want to create a development environment to make a couple of tests.

And now we have our new test folder created here.

Either you want to do everything with the command line, or maybe even better, you want to use the graphical interface from VS Code to browse your file as usual.

So you click at the top, open folder.

And here you can see the test directory I just created.

Now VS Code is opening again, but this time in the specific folder I mentioned.

And from now on, you can start developing as usual, as if you were on your local machine, except that your code is going to be executed on AWS.

So let's have a try.

For example, let's create a simple Python program, saying hello, new file, test.py, print, hello

Save the file.

And then in your console, we can now execute the file.

Hello.

So you just successfully ran your first remote code on AWS.

That's all for today.

You can now use your remote development environment as much as you want.

Do not forget to turn off your AWS instance when you don't need it anymore.

And see you soon.