Skills2026年4月15日·1 分钟阅读

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 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 29/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Stage only
信任
信任等级:Established
入口
LocalStack Playbook
安全暂存命令
npx -y tokrepo@latest install 8fa265fe-38ef-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

TL;DR
LocalStack emulates 80+ AWS services in one Docker container for local dev and CI.
§01

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.

§02

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.

§03

How to use

  1. Install LocalStack via pip or Docker Compose.
  2. Start the container with localstack start or docker-compose up.
  3. Point your AWS SDK to the LocalStack endpoint (http://localhost:4566).
  4. 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
§04

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'
§05

Related on TokRepo

§06

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 SERVICES is optional in newer versions. LocalStack now lazily loads services on first request.

常见问题

Which AWS services does LocalStack support?+

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.

Is LocalStack free to use?+

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.

How do I connect my AWS SDK to LocalStack?+

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.

Can I use LocalStack in CI pipelines?+

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.

Does LocalStack persist data between restarts?+

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)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产