Skip to content

An end to end guide for spinning up a self-managed EC2 instance running Ubuntu Desktop and connecting via VS Code.

Notifications You must be signed in to change notification settings

dnewingh/ubuntu-desktop-remote-development-starter-guide-pc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Introduction

This is a guide for setting up a remote development environment with VS Code inspired by the conceptual illustration below. This guide assumes the Local OS is Windows and the Remote OS is Linux. Additional emphasis is placed on setting up a cloud based on-demand environment where the Remote OS can be easily stopped when not in use. PowerShell Script Screenshot

Background

Remote development paradigms are great. This VS Code article presents a laundry list of several benefits but here are the main points for me.

  • Access to a UNIX based operating system (key for me as primarily a Windows user)
  • Keeps Local OS clean (e.g. no need to bog down your local workstation with Docker etc)
  • Faster than your laptop (with on demand access to more compute and storage)

Despite the benefits, there are also some things about remote development that I find a bit annoying.

  • No auto-hibernation and therefore incurring cost while remote machines are idle
  • No desktop GUI (this sucks because I like to run E2E tests with Puppeteer)
  • No automated provisioning and therefore cumbersome spin up and tear down

Recently I took a fresh look at three different options (Codespaces, Cloud9, and Self-managed EC2) in search of a solution to these annoyances. Here it the top line comparison.

Github Codespaces AWS Cloud9 Self-managed EC2
Auto-hibernation Included Requires customization (for VS Code) Requires customization
Desktop GUI Not Included Not Included Included
Automated provisioniong Included Included Requires customization
Operating Costs (2 cores 4-8GB RAM) $0.18/hr $0.96/hr $0.14/hr

Enterprise users may have different needs, but for me as a casual developer looking for a performant yet cost-effective Unix-based development environment with desktop GUI, a Self-Managed EC2 instance is what I am mostly using. Admittedly the setup is a pain. So, the rest of this guide will outline the steps I followed to setup Ubuntu Desktop as a Self-Managed EC2 instance.

Design

The diagram below illustrates the core system interactions that will be implemented with this guide.

Remote OS setup on AWS

Prequisites

Step 1: Configure AWS account administration

Step 2: Spin up EC2 instance

Step 3: Verify Remote OS Setup

  • Connect to EC2 instance via RDP by opening a new browser tab and entering the public IP of your instance (e.g. https://18.245.21.43 where 18.245.21.43 is the public IP address of the instance). The default user is ubuntu and the default password is the instance ID.
    • Launch a terminal session and confirm ssm agent is running with the following commands
      $ sudo snap list amazon-ssm-agent
      $ sudo snap services amazon-ssm-agent
  • Exit the RDP session

Configure Local OS

Prequisites

Step 1: AWS CLI Configuration

$ aws configure --profile remote-dev-admin
AWS Access Key ID [None]: YOUR_ADMIN_IAM_USER_ACCESS_KEY_CREATED_ABOVE
AWS Secret Access Key [None]:  YOUR_ADMIN_IAM_USER_SECRET_KEY_CREATED_ABOVE
Default region name [None]: us-east-1
Default output format [None]: json

Step 2: Test EC2 startup script

  • Copy the ec2-startup-script.ps1 file from this repo to your local OS and update line 1 with YOUR_EC2_INSTANCE_ID. This script will boot up you EC2 instance and launch an RDP session in the browser
  • Run ec2-startup-script.ps1 and leave PowerShell window running in the background

Step 3: VS Code configuration

Host ubuntu-desktop-on-EC2-001
    IdentityFile ~/.ssh/YOUR_KEY_PAIR.pem
    User ubuntu
    ProxyCommand C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "aws ssm start-session --profile remote-dev-admin --target YOUR_INSTANCE_ID --document-name AWS-StartSSHSession"
  • Open connection

Step 4: Shutdown

  • When you are finished working in VS Code return to the PowerShell window and enter q to trigger the command that will shutdown your remote OS PowerShell Script Screenshot

Conclusion

Message me if you give this a try or if you use something similar. I'd love to hear how others feel about this paradigm.

Troubleshooting

First Time Connect

  • You can reach your desktop environment through a Remote Desktop Client (such as the Microsoft Remote Desktop Application). The hostname is simply the public IP (or private IP for enterprise VPCs). Make sure you enter the username and password before you connect. On Windows, click "Show Options" and fill in the username (ubuntu), click "Allow me to save credentials", click "Connect", enter password (your instance ID) when prompted, click yes when prompted to connect despite certificate errors.

Inspiration

Optional

License

MIT

About

An end to end guide for spinning up a self-managed EC2 instance running Ubuntu Desktop and connecting via VS Code.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages