DEV Community

Romero Dias
Romero Dias

Posted on

2

Utilizando o S3 com LocalStack via Docker Compose

🛠️ Utilizando o S3 com LocalStack via Docker Compose

📌 Objetivo

Este guia ensina como:

  • Subir o LocalStack usando Docker Compose
  • Criar buckets S3 locais
  • Interagir com o S3 usando a AWS CLI
  • Usar o S3 local em sua aplicação (ex: Java/Spring Boot)

✅ Pré-requisitos

  • Docker e Docker Compose instalados
  • AWS CLI instalado
  • Editor de texto ou IDE

📁 Estrutura do Projeto

├── docker-compose.yml
├── localstack/
└── README.md (opcional)


🧱 1. Criar o docker-compose.yml

version: '3.8'

services:
  localstack:
    image: localstack/localstack:latest
    container_name: localstack
    ports:
      - "4566:4566"
    environment:
      - SERVICES=s3
      - DEBUG=1
      - DATA_DIR=/tmp/localstack/data
      - AWS_ACCESS_KEY_ID=test
      - AWS_SECRET_ACCESS_KEY=test
      - DEFAULT_REGION=us-east-1
    volumes:
      - ./localstack:/tmp/localstack
      - /var/run/docker.sock:/var/run/docker.sock
Enter fullscreen mode Exit fullscreen mode

2. Subir o ambiente

docker-compose up -d

3. Configurar a AWS CLI

Execute:

aws configure

Use credenciais fictícias:

AWS Access Key ID [None]: test
AWS Secret Access Key [None]: test
Default region name [None]: us-east-1
Default output format [None]: json
Enter fullscreen mode Exit fullscreen mode

4. Criar e manipular buckets S3

aws --endpoint-url=http://localhost:4566 s3 mb s3://meu-bucket
Enter fullscreen mode Exit fullscreen mode

Listar buckets:

aws --endpoint-url=http://localhost:4566 s3 ls
Enter fullscreen mode Exit fullscreen mode

Listar arquivos no bucket:

aws --endpoint-url=http://localhost:4566 s3 ls s3://meu-bucket/
Enter fullscreen mode Exit fullscreen mode

5. Configurar aplicação Java/Spring Boot

No application.properties:

cloud.aws.credentials.accessKey=test
cloud.aws.credentials.secretKey=test
cloud.aws.region.static=us-east-1
cloud.aws.s3.endpoint=http://localhost:4566
Enter fullscreen mode Exit fullscreen mode

Conclusão.

Com esse setup, você consegue simular o serviço S3 localmente com o LocalStack para testes e desenvolvimento, sem custos e com agilidade.

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay