Finding Your Fit: Crafting Diverse Development Environments on AWS Lightsail
Tags: aws, development, linux, productivity
Published: 2023-11-03 13:02:53

:bulb:**Exploring new development environments? AWS Lightsail offers cost-effective access to Windows and Linux operating systems. While primarily focusing on Windows connecting to Linux, this guide offers pathways for all. Get hands-on and explore a range of development opportunities affordably and flexibly. This guide helps you start, connect, and set up an alternative environment that suits your needs.**

### :clipboard:Table of Contents

- [Introduction](#introduction)
- [Working in a Windows Environment: Exploring WSL and Its Limitations](#working-in-a-windows-environment-exploring-wsl-and-its-limitations)
- [Building Your Own Linux Development Environment](#building-your-own-linux-development-environment)
    - [Prerequisites](#prerequisites)
    - [Setting up an AWS Lightsail Instance](#setting-up-an-aws-lightsail-instance)
    - [Connecting to Your Lightsail Instance with VS Code](#connecting-to-your-lightsail-instance-with-vs-code)
    - [Configuring the Development Environment](#configuring-the-development-environment)
- [Understanding Costs: AWS Lightsail Billing](#understanding-costs-aws-lightsail-billing)
- [Final Thoughts and Considerations](#final-thoughts-and-considerations)

---
### Introduction

My everyday machine is Windows, serving me well for most tasks. However, I found it limiting for code development and AWS interactions. Navigating through PowerShell and the absence of essential CLI tools became obstacles (could you live without [these cli tools](https://dev.to/lissy93/cli-tools-you-cant-live-without-57f6)?). This isn't about pitting one OS against another, but about enabling a smoother development journey. Here, I'll share a straightforward method to establish a Linux-based development environment. 

---
:cloud: Utilizing AWS credits, I explored a cost-saving solution. This guide showcases how to set up a Linux environment on AWS Lightsail, offering an alternative OS for developers seeking flexibility. While I focus on enabling Linux for Windows users, Lightsail provides [various OS](https://lightsail.aws.amazon.com/ls/docs/en_us/articles/compare-options-choose-lightsail-instance-image) types for diverse developer needs. 

---

:exclamation:**This solution will incur monthly charges that you have to be aware of (see the [Understanding Costs: AWS Lightsail Billing](#understanding-costs-aws-lightsail-billing)).**

---

### Working in a Windows Environment: Exploring WSL and Its Limitations
While an apparent and straightforward alternative is using WSL on Windows ([see here for setup instructions](https://learn.microsoft.com/en-us/windows/wsl/install)), my experience in Python and AWS SAM development revealed potential drawbacks. WSL often becomes unresponsive due to memory management inefficiencies. The memory allocation within WSL, managed by the Windows operating system, can lead to performance degradation and unresponsiveness, particularly evident when handling resource-intensive tasks in development environments. Despite my mighty 32GB RAM machine, every time I unleash `sam local start-api` with a medley of Lambda function fiestas, my WSL slowly morphs into the 'Snail Subsystem for Linux.' It huffs, puffs, and eventually naps, leaving me in the lurch. :blush:

### Building Your Own Linux Development Environment

#### :anchor: Prerequisites
- An AWS Account
- VS Code on your Windows machine

#### :computer: Setting up an AWS Lightsail Instance
1. Open Lightsail Console. And choose **Create instance**
![lightsail_console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ai3m2gefalgcliyww5n.png)
2. Choose the **OS Only** and your preferred Linux Distribution.
3. Use either the Default key or create/upload your own. Download the key.
4. Choose the instance plan. I wouldn't the smallest one, since it has only 512 MB of RAM. Go with a bit larger one. Give it a name, tags, and launch. After a couple of minutes, it'll be in the *Running* state.:zzz:

![running_instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lfiyhvatrxhmyvwz3m96.png)

5. Time for some additional setup. Choose your instance and go to the **Networking** tab. I would recommend attaching a static IP so that you can easily reconnect to your instance. You can remove the HTTP rule from the IPv4 Firewall, we'll be connecting through SSH. Configure the SSH rule to allow connections only from your IP (you can keep the *Allow Lightsail browser SSH* option enabled so that you can easily connect to your instance through the AWS Console). Check your IP and replace it as Source IP:
![firewall](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1anw43y5j9n8kght6uix.png)
You might want to disable the IPv6 networking if you're not planning on using it.

#### Connecting to Your Lightsail Instance with VS Code

1. Store locally the SSH Key from the Lightsail console. Remember the path to the `.pem` file.
2. Start Visual Studio Code.
3. Install the **Remote Explorer** extension through the **Extensions** menu.
![remote_explorer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5n5b3cuh368xdv8a61jk.png)
4. You should see the *Open a Remote Window* icon on the left bottom of VS Code.
![vscode_remote](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z10ncq9jvemt4o72jfig.png)
Click on it and then choose Connect to Host.
![vscode_connect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bh5yzp21unvzlfc377rt.png)
And then Add New Host.
![host](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zv9vymc5rtehl7pw69tq.png)
Give it a name like `ubuntu@<your.lightsail.static.ip>`. Select SSH configuration file or create it (on Windows it's usually stored at `C:\Users\{USERNAME}\.ssh\config`.
The config file will open and then specify the path to the SSH key or rename the host if you want:
![host_name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/znya11wj5wj1etq2xy6k.png)
5. Press F1 or Ctrl+Shift+P to open the command palette in VS Code.
Type and select "Remote-SSH: Connect to Host...".
Choose your Host. Choose Linux. Accept the fingerprint. 
:checkered_flag: And voila! You're connected!

![ssh_connected](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z8zi96o1rwqzo9i0k8g4.png)

6. Using the left menu bar you can choose Explorer -> Open Folder to browse the instances file system:

![explorer_files](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ex3j7537k98bl98o7uop.png)

#### :construction: Configuring the Development Environment

1. Access the Terminal within Visual Studio Code:
Once connected to your Lightsail instance via SSH in VS Code, go to the top menu and select Terminal > New Terminal. This action will open a new terminal window within VS Code, connected to your Lightsail instance.
2. Start off with updating and upgrading the packages (below commands for Ubuntu):
```bash
sudo apt update
```
```bash
sudo apt upgrade
```
3. Depending on your needs you might want to download additional packages. Ubuntu image comes with Python 3.10 installed.
4. Let's install AWS CLI
Install unzip
```bash
sudo apt install unzip
```
Download the AWS CLI
```bash
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
```
Unzip the downloaded package:
```bash
unzip awscliv2.zip
```
Run the installation script:
```bash
sudo ./aws/install
```
Verify the installation:
```bash
aws --version
```
### Understanding Costs: AWS Lightsail Billing  
:dollar: One important aspect to note is that charges apply not only to actively running instances but also to stopped instances. Whether your Lightsail instance is actively running or stopped, you'll incur charges. According to Lightsail's documentation:
> Q: When am I getting charged for a plan?
> Your Lightsail instances are charged only when they're in the running or stopped state. If you delete your Lightsail instance before the end of the month, we only charge you a prorated cost, based on the total number of hours that you used your Lightsail instance.

AWS [bills](https://lightsail.aws.amazon.com/ls/docs/en_us/articles/understanding-your-amazon-lightsail-bill) the instances by the hour, but advertises the monthly price by capping it for a whole month. For example, if you use a $5/1GB per month plan for 5 days, you will be charged 120 hours (5 days x 24 hours) at an hourly rate of $0.00672 (10 USD / 720 hours)(depending on the AWS Region). This amounts to $0.81 for 5 days of usage. More details on additional costs can be found [here](https://aws.amazon.com/lightsail/faq/#Billing_and_account_management).
:star: But remember that the first three months are free! :star:

### Final Thoughts and Considerations

:scroll: Cloud-based development environments offer enhanced productivity and flexibility. You can connect to your Linux instance on Lightsail from any machine supporting SSH and have a separate environment fitting your needs. Since there are many OS options to choose from you can start a Windows machine if that's what you need. While Windows Subsystem for Linux (WSL) is free, AWS Lightsail's Linux environment incurs additional costs. The crucial consideration is enabling both Linux users to initiate Windows and vice versa, balancing the limitations of local setups against the incurred expenses of cloud alternatives.

---
*Cover image generated with AI. Content credentials: Generated with AI ∙ November 3, 2023 at 11:57 AM.*