DEV Community

Cover image for Finding Your Fit: Crafting Diverse Development Environments on AWS Lightsail
Leszek Ucinski
Leszek Ucinski

Posted on

Finding Your Fit: Crafting Diverse Development Environments on AWS Lightsail

๐Ÿ’ก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.

๐Ÿ“‹Table of Contents


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?). 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.


โ˜๏ธ 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 types for diverse developer needs.


โ—This solution will incur monthly charges that you have to be aware of (see the 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), 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. ๐Ÿ˜Š

Building Your Own Linux Development Environment

โš“ Prerequisites

  • An AWS Account
  • VS Code on your Windows machine

๐Ÿ’ป Setting up an AWS Lightsail Instance

  1. Open Lightsail Console. And choose Create instance lightsail_console
  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.๐Ÿ’ค

running_instance

  1. 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 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
  4. You should see the Open a Remote Window icon on the left bottom of VS Code. vscode_remote Click on it and then choose Connect to Host. vscode_connect And then Add New Host. host 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
  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. ๐Ÿ And voila! You're connected!

ssh_connected

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

explorer_files

๐Ÿšง 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):
sudo apt update
Enter fullscreen mode Exit fullscreen mode
sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode
  1. Depending on your needs you might want to download additional packages. Ubuntu image comes with Python 3.10 installed.
  2. Let's install AWS CLI Install unzip
sudo apt install unzip
Enter fullscreen mode Exit fullscreen mode

Download the AWS CLI

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Enter fullscreen mode Exit fullscreen mode

Unzip the downloaded package:

unzip awscliv2.zip
Enter fullscreen mode Exit fullscreen mode

Run the installation script:

sudo ./aws/install
Enter fullscreen mode Exit fullscreen mode

Verify the installation:

aws --version
Enter fullscreen mode Exit fullscreen mode

Understanding Costs: AWS Lightsail Billing

๐Ÿ’ต 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 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.
โญ But remember that the first three months are free! โญ

Final Thoughts and Considerations

๐Ÿ“œ 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.

Top comments (1)

Collapse
 
robinamirbahar profile image
Robina

Amazing