Run AWS locally with LocalStack

Posted on April 23, 2025
Profile
Gastón Gaitan
April 23, 2025 · 1 month, 3 weeks ago
Run AWS locally with LocalStack

Getting Started with LocalStack and Docker

LocalStack is a fully functional local AWS cloud stack. It allows you to develop and test your cloud and serverless applications without connecting to a real AWS environment. LocalStack emulates a wide range of AWS services like S3, DynamoDB, Lambda, and more.

Why Use LocalStack?

Running AWS services locally provides faster feedback loops, lower costs, and the ability to work offline. With LocalStack, you can create, test, and validate your AWS infrastructure and business logic in an isolated environment before pushing to production.

Running LocalStack with Docker

The easiest way to use LocalStack is through Docker. If you have Docker installed, you can start LocalStack with a single command:

docker run --rm -it -p 4566:4566 -e SERVICES=dynamodb localstack/localstack

This command will:

  • Download the localstack/localstack image if it’s not already available locally.
  • Expose port 4566, the unified gateway for all AWS services in LocalStack.
  • Start only the DynamoDB service (you can add more if needed).
LocalStack Docker Networking Diagram

Creating a DynamoDB Table

Once LocalStack is running, use the AWS CLI to create a table:

aws --endpoint-url=http://localhost:4566 dynamodb create-table \
  --table-name MyTable \
  --attribute-definitions AttributeName=PK,AttributeType=S \
  --key-schema AttributeName=PK,KeyType=HASH \
  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

Inserting an Item

Insert a new item with:

aws --endpoint-url=http://localhost:4566 dynamodb put-item \
  --table-name MyTable \
  --item '{"PK": {"S": "topic#123"}, "name": {"S": "My First Topic"}, "questionsTotal": {"N": "0"}}'

Conclusion

LocalStack is a powerful tool for local AWS development. Docker makes it easy to run anywhere, and the CLI lets you work with your services just like on the real cloud. This approach ensures that your infrastructure logic works as expected before reaching production.

Tip: You can also use LocalStack with Terraform, AWS SDKs, and Python tools like boto3 to simulate full workflows.