LocalStack is a fully functional local AWS cloud stack that allows you to develop and test AWS applications locally without deploying to AWS. It emulates AWS services like S3, EC2, Lambda, DynamoDB, and many others on your local machine using Docker.
# 1. Install AWS CLI wrapper for LocalStack
pip install awscli-local
# 2. Start LocalStack
docker-compose up -d
# 3. Verify it's running (should return empty list)
awslocal s3 ls- Prerequisites
- Installation
- Configuration
- Running LocalStack
- Example AWS CLI Commands
- Data Persistence
- Available Ports
- Project Structure
- Troubleshooting
Before you can use this LocalStack setup, ensure you have the following installed:
- Docker: Version 20.10 or later (Install Docker)
- Docker Compose: Version 1.29 or later (Install Docker Compose)
- Python: Version 3.7 or later (for
awscli-local)
- Basic knowledge of AWS services (S3, EC2, Lambda, etc.)
- Familiarity with Docker and command-line tools
# Check Docker version
docker --version
# Check Docker Compose version
docker-compose --versionawscli-local is a wrapper around the AWS CLI that automatically redirects commands to your local LocalStack instance.
pip install awscli-localVerify the installation:
awslocal --versionEnsure you have the following files in your project directory:
- docker-compose.yml: Contains the LocalStack service configuration
- .env: Contains your LocalStack authentication token
If these are missing, see the Configuration section below.
The .env file contains your LocalStack Pro authentication token. This token grants you access to LocalStack Pro features.
Example .env:
LOCALSTACK_AUTH_TOKEN=ls-fOMIKusU-SUmA-retI-Nogi-RIbe19454f5b
What is LOCALSTACK_AUTH_TOKEN?
- It's your authentication token for LocalStack Pro
- It enables access to advanced AWS service emulations and additional features
- Keep this token secure and do not commit it to version control
Getting Your Token:
- Create a free account at app.localstack.cloud
- Navigate to your account dashboard
- Generate or copy your authentication token
- Paste it into your
.envfile as shown above
Security Note: Add .env to your .gitignore file to prevent committing sensitive tokens to version control.
The docker-compose.yml file defines the LocalStack service and its configuration:
Key Components:
| Component | Purpose |
|---|---|
| Image | localstack/localstack-pro - The LocalStack Pro Docker image (use localstack/localstack for Community edition) |
| Ports | 4566 - Main LocalStack endpoint; 4510-4559 - Additional service endpoints |
| Environment Variables | Configure LocalStack behavior (debug, auth, DNS settings) |
| Volumes | Mount Docker socket for nested container support; persist data to ./localstack-data |
Environment Variables:
DEBUG=1: Enable debug logging for troubleshootingDOCKER_HOST: Allows LocalStack to start containers (nested Docker)LOCALSTACK_AUTH_TOKEN: Your authentication token (loaded from .env)DNS_ADDRESS=0: Use default DNS settings
# Start in the background
docker-compose up -d
# Or start in foreground to see logs
docker-compose up# Check if the container is running
docker ps | grep localstack
# Test connectivity to LocalStack
awslocal s3 lsIf successful, the command will return an empty list (you haven't created any buckets yet).
- Main endpoint:
http://localhost:4566 - Additional services:
http://localhost:4510-4559
docker-compose down# View current logs
docker-compose logs -f localstack
# View last 100 lines
docker-compose logs --tail=100 localstackOnce LocalStack is running, you can use awslocal to interact with AWS services locally.
# Create a bucket
awslocal s3 mb s3://my-test-bucket
# List all buckets
awslocal s3 ls
# Upload a file
awslocal s3 cp myfile.txt s3://my-test-bucket/
# List bucket contents
awslocal s3 ls s3://my-test-bucket/
# Download a file
awslocal s3 cp s3://my-test-bucket/myfile.txt ./downloaded-file.txt# Create a table
awslocal dynamodb create-table \
--table-name Users \
--attribute-definitions AttributeName=id,AttributeType=S \
--key-schema AttributeName=id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST
# List tables
awslocal dynamodb list-tables
# Put an item
awslocal dynamodb put-item \
--table-name Users \
--item '{"id": {"S": "user123"}, "name": {"S": "John Doe"}}'# List functions
awslocal lambda list-functions
# Create a function (requires a zip file)
awslocal lambda create-function \
--function-name my-function \
--runtime python3.9 \
--role arn:aws:iam::000000000000:role/lambda-role \
--handler index.handler \
--zip-file fileb://function.zipLocalStack stores data in the ./localstack-data directory, which is mounted as a volume in the Docker container.
localstack-data/
├── cache/ # LocalStack cache files
│ ├── certs/ # SSL certificates for HTTPS
│ ├── license.json # License information
│ └── machine.json # Machine configuration
├── lib/ # Library files
├── logs/ # LocalStack logs (if configured)
└── tmp/ # Temporary files
- Enabled by default: Data persists between container restarts
- Data preserved in volumes: Buckets, tables, functions, etc., remain even after
docker-compose down - Clean slate: To reset all data, delete the
localstack-datadirectory or run a reset command (see Troubleshooting)
| Port | Purpose |
|---|---|
| 4566 | Main LocalStack endpoint (S3, DynamoDB, Lambda, etc.) |
| 4510-4559 | Additional service-specific endpoints (reserved for future use) |
All services can be accessed via the main endpoint (4566). The additional ports are available if needed for specific configurations.
localstack/
├── docker-compose.yml # Docker Compose configuration file
├── .env # Environment variables (authentication token)
├── README.md # This file
├── localstack-data/ # Data persistence volume
│ ├── cache/ # Cache and certificates
│ ├── lib/ # Library files
│ ├── logs/ # Log files
│ └── tmp/ # Temporary files
- docker-compose.yml: Defines the LocalStack service configuration, ports, volumes, and environment variables
- .env: Contains sensitive configuration (authentication token) - do not commit to Git
- README.md: Project documentation (this file)
- localstack-data/: Volume mount directory for persistent data storage
Problem: docker-compose up fails with "port is already allocated"
Solution:
- Identify what's using port 4566:
netstat -ano | findstr :4566 - Either stop the conflicting service or change the port in
docker-compose.yml:ports: - "4567:4566" # Map 4567 on host to 4566 in container
Problem: Commands fail with authentication errors
Solution:
- Verify your token is correct in
.env - Ensure
.envis in the same directory asdocker-compose.yml - Regenerate your token at app.localstack.cloud
- Update
.envwith the new token - Restart LocalStack:
docker-compose down && docker-compose up -d
Problem: awslocal commands fail to connect
Solution:
- Verify LocalStack is running:
docker ps | grep localstack - Check logs for errors:
docker-compose logs localstack
- Ensure Docker daemon is running
- On macOS/Windows, ensure Docker Desktop is started
Problem: Docker commands fail
Solution:
- Docker Desktop: Start the Docker Desktop application
- Linux: Ensure Docker daemon is running:
sudo systemctl start docker - Permission denied: Add your user to Docker group:
sudo usermod -aG docker $USER
Problem: Trying to use a service that doesn't exist or isn't emulated
Solution:
- Check LocalStack Pro Supported Services
- Verify you're using LocalStack Pro (for extended service support)
- Update LocalStack image:
docker pull localstack/localstack-pro
To enable debug logging for troubleshooting, the setup already has DEBUG=1 enabled. View detailed logs:
docker-compose logs -f localstack | grep -i errorTo start fresh with no data:
# Stop the container
docker-compose down -v
# Remove the data directory
rm -rf localstack-data
# Start fresh
docker-compose up -dWarning: This will delete all data (buckets, tables, functions, etc.)
To use the free Community edition instead of Pro:
-
Edit
docker-compose.yml:image: localstack/localstack # Change from localstack-pro
-
Remove the
LOCALSTACK_AUTH_TOKENenvironment variable (or leave it blank) -
Restart:
docker-compose down && docker-compose up -d
- ✅ Verify prerequisites are installed
- ✅ Install
awscli-local - ✅ Start LocalStack with
docker-compose up -d - ✅ Test connectivity with
awslocal s3 ls - ✅ Try example commands from Example AWS CLI Commands
- ✅ Explore LocalStack documentation for advanced features