Testing with LocalStack: AWS on your Laptop

If you build on AWS, you need **LocalStack**. It mocks almost every AWS service (S3, Lambda, DynamoDB, SQS) on your local machine via Docker, allowing for free, fast, and offline development.

Docker Compose Setup

version: '3.8'
services:
  localstack:
    image: localstack/localstack
    ports:
      - "4566:4566" # The single edge port
    environment:
      - SERVICES=s3,sqs,dynamodb
      - DEFAULT_REGION=us-east-1

Configure AWS SDK (.NET)

var config = new AmazonS3Config
{
    ServiceURL = "http://localhost:4566",
    ForcePathStyle = true // Crucial for LocalStack S3
};
var s3 = new AmazonS3Client("test", "test", config);

Key Takeaways

  • Use `awslocal` CLI wrapper for convenience: `awslocal s3 ls`.
  • Great for testing IAM policies and infrastructure code (Terraform runs against it too!).

Discover more from C4: Container, Code, Cloud & Context

Subscribe to get the latest posts sent to your email.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.