Remote development with Amazon EC2 and VSCode

Several months ago, I needed to generate tests for one of my plugins, which required setting up WordPress environments using Docker. We all know that Docker instances consume significant CPU and RAM. Despite having sufficient resources on paper, when I ran the tests, my entire system nearly froze and I wasn’t able to do any other task. I’ve been contemplating this idea of remote development for a while and thought it might be time to give it a go. Now for the most part of my job, I’m doing remote development on an Amazon server, which alleviates the strain on my laptop.

Watch a video version of this tutorial:

Is there other workarounds?

Obviously, the first one was to upgrade my laptop and buy a better one. Of course with 12GB of ram, you can not go so far and you either need more ram or better technology. The main reason I didn’t buy a new laptop was that a good laptop that can handle everything is not that cheap. On the other hand, this part of my tasks was not a permanent thing and after I finished it, I probably wouldn’t need to use docker and the instances for a while.

Remote development on Amazon servers

Basically for remote development, you need a server that is maintained by other people and the OS can be anything (mostly by your choice). You can decide what the specifications of the server should be. You can also upgrade them whenever you want. Isn’t this great?!

After some research and of course comparing prices, I finally founded a good option for my remote development server, Amazon EC2!

What is Amazon EC2?

What we need to know is that they are basically virtual servers or (as they call it) instances and you can treat them like a real system. You can run programs on them, save files and most importantly, develop your stuff.

Create an EC2 instance

The first step is to go to Amazon AWS and create an account and after that, sign in to the console. It’s free and you can also have a free instance. Although it’s not that powerful, you can use it to test the servers and see if they are good.

After you sign in to the amazon aws console, you will see a page like this:

amazon remote servers

We don’t want to make things complicated for now and we just want to have a server. So click on the EC2 link and you will see the EC2 dashboard. There are a lot of useful information on this page that you can use.

You should see a yellow button called “Launch instance”. If you don’t see it, on the left hand menu, click on the instances and on the next page, click on “Launch instance”. You would see a page like this:

amazon ec2 launch instance

You can enter a name for your instance and you can choose an operating system for it. Ubuntu can be a good option to start your remote development. Next, on the “Amazon Machine Image (AMI)” section, select the version of Ubuntu that you want to install.

In the “Instance type” section, you can choose the amount of RAM and CPU for your server. Just click on the instance that is selected and you will see a long list of servers.

development servers on amazon

Ad you can see, I have chosen a server that has 32 GB of ram and it’s going to charge 52 cents per hour.

The next step is creating a key. On the “Key pair” section, click on the “Create new key pair” and you will see a screen like this:

create key pair amazon ec2

Enter a name for the key file and leave the other options in their default value. Click on the “Create key pair” value. It downloads the private key on your website and we will need this key to connect to the server with VSCode.

On the “Network settings” tab, you can either allow any IP to access your server (with authentication) or specific IPs. If you don’t have a static IP, then a range of IPs or all IPs might be a good idea.

And lastly, you should setup the amount of storage that you want. The good point is that you can get 30 GBs of data for free. After this, your server will be created and you can see it in the list of your instances.

How to connect to Amazon EC2

On the left hand side menu, click on the instances and you would see a list of the instances that you have.

amazon ec2 list of instances

Select your instance and from the “Instance state” menu, start your instance if it’s already not started. Then while your instance is still selected, click on the “Connect” button and you will see a list of options for connecting to your server.

Click on the “SSH Client” tab and you will see a list of instructions. On the number 4, you can find the public DNS address of your website:

“Connect to your instance using its Public DNS:”

Save this address as we are going to need it for the next steps.

Setting up VSCode for remote development

In this article, I assume that you are using VSCode. However, if you’re using another IDE or code editor, the main thing is to look for the SSH part or install the extension.

For VSCode users, you need to go to the extensions center and install the “Remote – SSH” extension by Microsoft or the while “Remote development” pack. After you did, you should see a green icon at the bottom left of VSCode.

When you click on this, you will see the “Connect to Host” option and next, click on the “Configure SSH Hosts”. After this, add this to the config file:

Host Your-Preferred-Name
  HostName host-name.amazonaws.com
  User ubuntu
  IdentityFile ~/remote/key.pem

So from the previous steps, we copied a public DNS address and we have also downloaded the private key. In the HostName property, we need to enter the DNS address and for the IdentityFile we should enter the location of the private key file.

After this, we are ready to connect to the server. Click on the green icon again:

And this time, click on the name that you added in the previous step. It might ask you some questions to confirm the fingerprint or the OS and after that, you will be connected to the server.

Now that you are connected, you can click on the “Explorer” in VSCode and then select “Open Folder”. On the screen that opens, you can browse and choose a folder. Remember that you have a good file manager in VSCode that allows you to create folders to structure your work.

Some small things to note:

  • Your public DNS changes every time that you stop the instance, so you should update it in the config file.
  • If you stop the server, your files won’t be deleted.

Is remote development worth it?

It’s been a few months since I have started my remote development on Amazon servers and I feel quite good about it. To better understand the advantages and disadvantages of remote development on amazon servers, here’s a list of my thoughts:

Let me know what you think of remote development and if you have encountered any issues setting up your servers.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *