Visual Studio Code (VS Code) is an open source code editor developed by Microsoft. With build in support for most common languages and platforms, VS Code has become a go-to IDE for many developers. Now the open source project at coder.com has a new project that allows you to easily deploy VS Code editors to servers in the cloud, or in a managed instance. This project, called code-server, is available on GitHub here.
In this article, we will cover how to setup code-server on an AWS EC2 server and in future articles we will use this setup for our example projects.
- AWS Account
Setup EC2 Instance
Head on over to the EC2 dashboard and create a new instance. On the instance type select Ubuntu Server 16.04 LTS, as this is the latest supported Linux distro that code-server is tested on at the time of this article. For this example all the defaults are sufficient so just select next until you get to the Configure Security Group page. On the security group, add a new All Accept rule and then set the IP range to be your local computers IP address. This will allow only your computer to connect to the server and the VS Code instance. After setting up the security rules click Launch and on the next page create a new key pair and download the .pem file. Finally, click Launch Instances to create your EC2 server.
Open up your terminal emulator of choice (I have been using hyper of late) and navigate to the directory you downloaded your private key file too. Now execute the following commands to set up the key file with the correct permissions and then SSH connect to the EC2 instance.
sudo chmod 400 <pemkeyfile>.pem ssh -i "<pemkeyfile>.pem" <ec2_public_ip_address>
After connecting to the server execute the following commands to download the code-server code and startup the server. Go to the releases page and get the latest download link for the Linux release.
wget <release_link>.tar.gz tar -xf <release_link>.tar.gz cd code-server-<version> sudo ./code-server
Once the code server starts, navigate to the public IP address of your EC2 server with the port as specified in the console output of the last command above. Also included in that output will be the initial password to log in with, which can be changed later.
And if all went well you should be greeted with a VS Code window that looks like the following
In this short article, we saw how to set up a code-server instance to run the VS Code IDE on an AWS EC2 server. Moving forward we will build off this in future articles!