LocalStack — AWS Cloud Service Emulator for Local Development & CI
Run S3, Lambda, DynamoDB, SQS, SNS, IAM, and 80+ other AWS services on your laptop or CI runner in a single Docker container.
这个资产会安全暂存
这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。
npx -y tokrepo@latest install 8fa265fe-38ef-11f1-9bc6-00163e2b0d79 --target codex先暂存文件;激活前需要读取暂存 README 和安装计划。
What it is
LocalStack is a cloud service emulator that runs inside a single Docker container on your laptop or CI runner. It provides functional implementations of over 80 AWS services including S3, Lambda, DynamoDB, SQS, SNS, IAM, and more. Instead of deploying to AWS for every test, you point your SDK at LocalStack and iterate locally.
This tool is built for backend developers, DevOps engineers, and platform teams who need fast feedback loops without incurring AWS costs or waiting for cloud provisioning.
How it saves time or tokens
LocalStack eliminates the deploy-test-debug cycle against real AWS. A Lambda function that takes 2 minutes to deploy and test on AWS can be tested in seconds locally. CI pipelines run faster because they skip network round-trips to AWS endpoints. Teams also avoid surprise AWS bills from forgotten test resources.
For AI-assisted development, LocalStack lets coding agents test AWS integrations without needing real credentials or permissions, keeping the feedback loop tight.
How to use
- Install LocalStack via pip or Docker Compose.
- Start the container with
localstack startordocker-compose up. - Point your AWS SDK to the LocalStack endpoint (
http://localhost:4566). - Run your application or tests against the local endpoints.
# Start LocalStack with Docker
docker run --rm -it -p 4566:4566 localstack/localstack
# Create an S3 bucket locally
aws --endpoint-url=http://localhost:4566 s3 mb s3://my-test-bucket
# Put an object
aws --endpoint-url=http://localhost:4566 s3 cp test.txt s3://my-test-bucket/
# List buckets
aws --endpoint-url=http://localhost:4566 s3 ls
Example
A typical docker-compose.yml for LocalStack:
version: '3.8'
services:
localstack:
image: localstack/localstack
ports:
- '4566:4566'
environment:
- SERVICES=s3,lambda,dynamodb,sqs
- DEBUG=1
volumes:
- './localstack:/var/lib/localstack'
- '/var/run/docker.sock:/var/run/docker.sock'
Then in your Python test:
import boto3
s3 = boto3.client('s3', endpoint_url='http://localhost:4566')
s3.create_bucket(Bucket='test-bucket')
s3.put_object(Bucket='test-bucket', Key='hello.txt', Body=b'Hello')
response = s3.get_object(Bucket='test-bucket', Key='hello.txt')
print(response['Body'].read()) # b'Hello'
Related on TokRepo
- DevOps tools — More infrastructure and deployment tools
- Self-hosted solutions — Other tools you can run locally
Common pitfalls
- Not all AWS API behaviors are perfectly replicated. Some edge cases in IAM policies or advanced Lambda features may differ from production AWS.
- The free Community edition covers most services, but certain enterprise features like EKS and RDS require LocalStack Pro.
- Docker socket mounting is required for Lambda execution with container runtimes. Forgetting this causes silent failures.
- Large-scale load testing against LocalStack does not reflect real AWS latency or throttling behavior.
- Environment variable
SERVICESis optional in newer versions. LocalStack now lazily loads services on first request.
常见问题
LocalStack supports over 80 AWS services including S3, Lambda, DynamoDB, SQS, SNS, IAM, CloudFormation, API Gateway, Kinesis, and Step Functions. The Community edition covers core services. Pro adds EKS, RDS, ElastiCache, and others.
The Community edition is free and open-source under Apache 2.0. It covers most common AWS services. LocalStack Pro is a paid tier that adds advanced services, persistence, and team collaboration features.
Set the endpoint URL to http://localhost:4566 in your SDK client configuration. For the AWS CLI, use the --endpoint-url flag. For SDKs like boto3, pass endpoint_url parameter when creating a client. Credentials can be any dummy values.
Yes. LocalStack runs as a Docker container, making it straightforward to add to GitHub Actions, GitLab CI, Jenkins, or any Docker-capable CI system. This eliminates the need for real AWS credentials in CI and speeds up integration tests.
By default, data is ephemeral and lost when the container stops. You can mount a volume to /var/lib/localstack for persistence. LocalStack Pro also offers a snapshot and restore feature for saving and loading state.
引用来源 (3)
- LocalStack GitHub— LocalStack emulates 80+ AWS services locally
- LocalStack Documentation— Docker-based cloud emulator for development and CI
- AWS SDK Documentation— AWS SDK endpoint configuration for local testing
讨论
相关资产
Floci — AWS Local Emulator Alternative
A lightweight AWS service emulator for local development and testing, providing fast startup and low resource usage as an alternative to LocalStack.
Finch — Open Source Container Development by AWS
Finch is an open-source container development tool by AWS that provides a seamless Docker-compatible CLI backed by containerd, nerdctl, and Lima.
AWS CDK — Define Cloud Infrastructure Using Real Programming Languages
The AWS Cloud Development Kit lets you define cloud infrastructure in TypeScript, Python, Java, Go, or C# instead of YAML templates. CDK synthesizes your code into CloudFormation and deploys it with a single command.
Cloud Nuke — Wipe AWS Resources with a Single Command
A CLI tool from Gruntwork for cleaning up AWS accounts by deleting all resources across regions. Cloud Nuke is essential for tearing down sandbox environments, reducing cloud costs, and preventing resource sprawl.