☁️ Local Cloud Computing: No Credit Card Needed! 🚀
Hey Devs! 👋
Cloud computing is exciting, but the idea of linking your credit card just to explore services? Not so much. Maybe you're afraid of waking up to a $1000 bill for doing nothing, or you just want a hands-on experience without financial stress.
That's where Local Cloud Computing comes in! 🌐💡
This is the first article in my series:
"☁️ Local Cloud Computing with LocalStack + Docker + AWS CLI 💡"
In this series, I will guide you through setting up a local cloud environment to run various cloud services locally on your system. 🚀
Here, I'll guide you through setting up everything so you can run cloud services locally—no cloud costs, no surprises.
💾 All code, docs, and resources are available in my GitHub repository:
This repository focuses on cloud computing and demonstrates how to set up virtual machines, S3, and other services using LocalStack. It provides a comprehensive guide to simulating AWS services locally for development and testing purposes.
Cloud-Computing
This repository focuses on cloud computing and demonstrates how to set up virtual machines, S3, and other services using LocalStack. It provides a comprehensive guide to simulating AWS services locally for development and testing purposes.
AWS Command Line Interface (CLI) is a powerful tool that allows users to interact with AWS services directly from the terminal. It simplifies managing cloud resources by providing commands for a wide range of AWS services, enabling tasks such as provisioning, managing, and automating workflows with ease.
LocalStack is a fully functional, local testing environment for AWS services. It enables developers to simulate AWS services on their local machines, facilitating the development and testing of cloud-based applications without needing access to an actual AWS account.
I’ll start by explaining the core concepts—LocalStack and its key components—so you have a clear understanding before diving into the setup.
Then, I’ll walk you through the step-by-step installation and configuration. And since no setup is complete without a few hiccups, I’ll also cover troubleshooting tips for every issue I encountered along the way.
💻 I did this entire setup on Windows, so if you're using Windows too, this guide should be extra helpful!
So, let’s dive in! 🚀
LocalStack
LocalStack is a local AWS cloud stack that provides a seamless development and testing environment. Here's a concise breakdown of its features and benefits:
AWS Service Simulation: Mimics AWS services like S3, EC2, Lambda, DynamoDB, and more.
Local Development: Enables developers to test and build cloud applications on their local machine without needing internet connectivity.
Cost-Free Environment: No AWS account or associated costs are required for running services locally.
API Compatibility: Provides APIs that replicate AWS functionalities, allowing easy integration with existing tools and workflows.
Isolated Testing: Facilitates isolated development and testing before deploying to the actual AWS cloud.
Automation and CI/CD: Perfect for automating workflows, testing infrastructure, and integrating with continuous integration/continuous deployment pipelines.
Installation Guide
Docker Setup
Since LocalStack uses Docker to simulate AWS services locally, follow these steps to install it:
During installation, ensure the following options are selected:
"Install required Windows components for WSL 2" (if using WSL 2).
Restart the machine if prompted to complete the installation.
2. Verify Docker Installation
Open a command prompt or PowerShell and run the following command to check if Docker is installed:
docker --version
If Docker is successfully installed, a version number will appear, for example: Docker version 24.0.2, build abcdef.
3. Start Docker Desktop
Launch Docker Desktop and wait until it indicates that "Docker is running."
4. Enable WSL 2 Integration (If Required)
If Docker is not running on Windows, enable WSL 2 by following these steps:
Open Docker Desktop settings.
Go to General and check the option "Use the WSL 2-based engine."
Apply the changes and restart Docker Desktop.
LocalStack Installation
Install LocalStack:
LocalStack can be installed via pip:
pip install localstack
Alternatively, it can be pulled from Docker:
docker pull localstack/localstack
Start LocalStack:
For running LocalStack with Docker:
docker run -d-p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack
If LocalStack is installed locally:
localstack start
Install AWS CLI:
If the AWS CLI is not already installed:
pip install awscli
Configure AWS CLI for LocalStack:
The AWS CLI can be configured using default credentials, as LocalStack does not require actual AWS credentials:
aws configure
Access Key ID: test
Secret Access Key: test
Region: us-east-1
To configure the AWS CLI to connect to LocalStack:
export AWS_ENDPOINT_URL=http://localhost:4566
During the aws configure setup, the AWS CLI will prompt for configuration details, including the output format, which controls the display style of results from AWS CLI commands.
Common Output Formats:
JSON (default): A structured data format, ideal for automation and scripting.
Example:
{"Key":"Value","AnotherKey":"AnotherValue"}
Table: A human-readable table format, ideal for quick reviews.
Text: A simple plain-text format, suitable for scripts or command-line parsing.
Example:
Key1 Value1
Key2 Value2
Choosing the Output Format
During the aws configure setup, users can:
Accept the default format by pressing Enter to select json.
Alternatively, specify a different format by typing one of the following:
json
table
text
Example:
Default output format [json]: table
How to Change the Output Format Later
If a user wishes to change the output format after the initial configuration, they can:
Manually edit the AWS CLI configuration file:
Open ~/.aws/config (on Linux/macOS) or %USERPROFILE%\.aws\config (on Windows).
Modify the output setting:
[default]
output = text
Use the --output flag when running commands:
aws s3 ls--output table
Resolving the Failed to connect to localhost port 4566 Error
When encountering the error Failed to connect to localhost port 4566, it typically indicates that no service is running on that port. To resolve this issue:
Check if LocalStack is Running:
To verify if LocalStack is running, users can check the container or process status by executing the following command:
docker ps
Verify Port Mapping and LocalStack Startup:
If using Docker, ensure the correct ports are mapped. If running LocalStack locally, users should confirm its successful startup by checking the logs or re-running the following command:
localstack start
Limitations in LocalStack
LocalStack should be considered a basic simulation of AWS EC2, as it does not support actual VM provisioning.
For working with real VMs locally, hypervisors such as VirtualBox or VMware should be used, or LocalStack should be integrated with these tools for a hybrid setup.
This setup should be considered suitable for testing and development in a simulated cloud environment, allowing API interactions and configuration testing without incurring cloud service costs.
Troubleshooting
Error Encountered:
C:\Windows\System32>pip install localstack
WARNING: Ignoring invalid distribution -treamlit(c:\users\rawat\
appdata\local\programs\python\python310\lib\
site-packages)
Collecting localstack
Using cached localstack-4.0.3.tar.gz (5.7 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting localstack-core (from localstack)
Using cached localstack_core-4.0.3-py3-none-any.whl.
metadata (5.4 kB)
Collecting localstack-ext==4.0.3 (from localstack)
Using cached localstack_ext-4.0.3.tar.gz (6.2 MB)
ERROR: Could not install packages due to an OSError:
[Errno 2] No such file or directory:
'C:\\Users\\rawat\\AppData\\Local\\Temp\\pip-install-
q450br39\\localstack-ext_771d2730449b461b8323becea
3af2ce5\\localstack/pro/core/services/lambda_/invocation
/endpoint_injection/java/SdkV2DisableCertificateValidation/
src/main/java/cloud/localstack/HttpClientTransformer.java'
HINT: This error might have occurred since this system does
not have Windows Long Path support enabled.
You can find information on how to enable this at
https://pip.pypa.io/warnings/enable-long-paths
The error indicates that Windows Long Path Support is not enabled, which is necessary because some files in the localstack installation exceed the default path length limit of 260 characters on Windows.
Here are the steps to resolve this:
Steps to Enable Windows Long Path Support
Enable Long Paths in the Windows Registry:
Open the Run dialog (Win + R), type regedit, and press Enter.
Check Python Compatibility: Ensure that the Python version is compatible with the localstack version being installed.
Issue with the export Command on Windows
The export command is used in Unix-based systems like Linux and macOS to set environment variables. However, it is not recognized in Windows Command Prompt (CMD). In CMD, the set command should be used instead to set environment variables.
To resolve the issue, replace the export command with the set command in CMD:
set AWS_ENDPOINT_URL=http://localhost:4566
Notes:
If using PowerShell, the environment variable can be set with the following command:
$env:AWS_ENDPOINT_URL="http://localhost:4566"
For a persistent environment variable across sessions, use the setx command to set it permanently:
setx AWS_ENDPOINT_URL "http://localhost:4566"
Caution: The variable set with setx will only be available in new CMD or PowerShell sessions.
To verify the environment variable is set correctly, run the following:
echo %AWS_ENDPOINT_URL%
This should display:
http://localhost:4566
Starting Services
1. Ensure the Service is Running
If LocalStack or another AWS emulator is being used, it's essential to confirm that it has started successfully.
For LocalStack:
localstack start
For Docker (if LocalStack is running via Docker):
docker run -p 4566:4566 -d localstack/localstack
After executing this, the following command can be used to confirm the container is running:
docker ps
2. Verify Port Availability
To check if another service is using port 4566, the following command should be run:
netstat -ano | find "4566"
If no output is returned, it indicates the port is free.
If output is returned, it's necessary to identify which process is using the port by executing:
tasklist /FI "PID eq <PID>"
Replace <PID> with the process ID found from the netstat output.
3. Check Firewall or Antivirus Settings
It should be ensured that no firewall or antivirus software is blocking connections to port 4566.
Temporarily disabling the firewall or antivirus can help in testing.
4. Confirm localhost Works
To check if localhost is working correctly on the system, the following command can be used:
ping localhost
If there is no response, replacing localhost with 127.0.0.1 is recommended:
set AWS_ENDPOINT_URL=http://127.0.0.1:4566
5. Validate curl Setup
It is crucial to confirm that curl is installed and functioning correctly by running:
curl --version
If curl is not found, it can be downloaded from curl's official website or enabled through Windows Features.
6. Restart System or Docker
A system restart and/or restarting Docker could help resolve any lingering issues.
After restarting, the desired service (e.g., LocalStack) should be started again.
7. Manually Test Another Port
To manually test connectivity to localhost, a simple web server can be run using the following command:
python -m http.server 4566
Then, the server can be accessed with:
curl http://localhost:4566
If this works, it suggests the issue lies with the service running on port 4566.
If it doesn’t work, there may be a network configuration issue.
Troubleshooting Docker Desktop Sign-Out Issues
If Docker Desktop keeps signing out automatically, several common causes and fixes should be considered:
1. Enable Trusted Root Certificates
Docker Desktop may fail to authenticate if the required root certificates are missing or untrusted.
Solution:
The system’s date and time should be confirmed to be correct.
The certificates can be updated by running the following command:
certutil -generateSSTFromWU roots.sst
The roots.sst file can then be double-clicked to install the certificates.
2. Clear Docker Credentials
Cached credentials might be causing the sign-out issues.
Solution:
Navigate to the Docker configuration folder:
C:\Users\<YourUsername>\.docker
The config.json file should be deleted.
Docker Desktop should be restarted, and the user should sign in again.
If Docker is not running, it should automatically troubleshoot and restart itself.
LocalStack Container Image Download Process
The following output indicates that LocalStack is attempting to pull the container image localstack/localstack to run in Docker mode, which suggests that the setup is working up to this point. Here's what's happening:
C:\Users\rawat>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Pulling container image localstack/localstack
What’s Happening?
LocalStack CLI Detected Docker Mode:
[11:20:31] starting LocalStack in Docker mode confirms that LocalStack is trying to run using Docker.
Container Image Not Found Locally:
[11:25:13] container image not found on host indicates that Docker is downloading the localstack/localstack image from Docker Hub since it’s not found locally.
Pulling the Container Image:
⠧ Pulling container image localstack/localstack confirms that the image download process is ongoing.
What to Expect Next
If the internet connection is stable, Docker should complete the download in a few minutes.
After the image is downloaded, LocalStack will initialize, and the services (e.g., S3, DynamoDB) will start. This will be confirmed by further logs.
How to Verify It’s Working
After the image download is complete, the user can check if the container is running with the following command:
docker ps
The container should be listed with the name localstack.
To verify that LocalStack is running, the endpoint should be accessed:
curl http://localhost:4566
A response should be returned, confirming that LocalStack is active.
If Pulling Takes Too Long
Check the internet speed and Docker's ability to pull images:
docker pull localstack/localstack
If the pull succeeds, proceed to rerun the LocalStack command:
After successfully pulling the image, run the following to verify:
C:\Users\rawat>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
localstack/localstack latest b686f3948f42 4 hours ago 1.18GB
hello-world latest 74cc54e27dc4 31 hours ago 10.1kB
If issues persist after pulling hello-world, follow these steps:
Start Docker Desktop.
Then, execute:
localstack start
✅ Hopefully, your LocalStack will now start successfully in the terminal with "LocalStack" displayed, and Docker will show all running containers.
📄 Want to see the output step by step? Check it out here:
These tutorials enhance your comprehension of LocalStack's functionality by providing detailed information on how it works for specific use cases using diverse resources. These guides help you set up and build your local cloud development & testing environment with the help of LocalStack, using local AWS services, integrations, and tools, helping create a mental model for how LocalStack works. For community contributed tutorials, check out the [LocalStack Community Tutorials](https://hashnode.localstack.cloud/).
docs.localstack.cloud
4. Blog Post on LocalStack Setup and Usage
Getting Started with LocalStack: Overview, Setup, and Practical Usage Guide
Discover LocalStack: Your local AWS cloud stack for efficient and cost-effective development and testing. Learn how to emulate AWS services like S3, DynamoDB, Lambda, and more on your local machine. Enhance your cloud development workflows with faster iteration cycles, comprehensive testing, and offline capabilities. Read our comprehensive guide on why LocalStack is a must-have tool for every developer working with AWS.
ruan.dev
💡 I hope this guide helped you! If you run into any issues, drop a comment—we’ll solve them together! 🕵️♂️
🔥 Stay tuned for the next article, where I'll explain how to set up a VM in this local cloud setup! 🚀
💬 Let me know your thoughts in the comments! 📝 Did you find this helpful? Was the setup smooth for you? This took me a lot of time to put together, and the setup was pretty hectic—especially on Windows! 😵💫 So, drop a like and a comment to show some love! 💛😊