#1
Dropwizard is a powerful and easy-to-use framework for building Java REST APIs. If you’re working with file uploads, backups, or media storage, integrating Amazon S3 is a smart choice. This guide shows you how to set up S3 in Dropwizard—using MinIO locally to simulate S3 and real AWS S3 in production—while keeping development and deployment clean, secure, and environment-aware.

1. Add Required Dependencies

First, include the following in your pom.xml:
<dependencies>
  <!-- Dropwizard -->
  <dependency>
    <groupId>io.dropwizard</groupId>
    <artifactId>dropwizard-core</artifactId>
    <version>${dropwizard.version}</version>
  </dependency>

  <!-- AWS SDK S3 support -->
  <dependency>
    <groupId>software.amazon.awssdk</groupId>
    <artifactId>s3</artifactId>
    <version>${aws.sdk.version}</version>
  </dependency>

  <!-- (Optional) Fabric8 for future Kubernetes control -->
  <dependency>
    <groupId>io.fabric8</groupId>
    <artifactId>kubernetes-client</artifactId>
    <version>${fabric8.version}</version>
  </dependency>
</dependencies>
This setup gives you Dropwizard, AWS S3 support, and optional Kubernetes integration for production.

2. Run MinIO Locally via Docker

Use MinIO as a local S3-like service for easy testing:
docker run -p 9000:9000 -p 9001:9001 \>  -e MINIO_ROOT_USER=minioadmin \
  -e MINIO_ROOT_PASSWORD=minioadmin \
  minio/minio server /data --console-address ":9001"
  • S3 endpoint: http://localhost:9000
  • Web console: http://localhost:9001

3. Dev Config: config-dev.yml

Create a development config file:
server:
  applicationConnectors:
    - type: http
      port: 8080

s3:
  endpoint: http://localhost:9000
  region: us-east-1
  accessKeyId: devuser
  secretAccessKey: devpass123
  bucketName: dev-bucket
  pathStyleAccess: true
Define configuration classes:
public class S3Config {
  @JsonProperty public String endpoint;
  @JsonProperty public String region;
  @JsonProperty public String accessKeyId;
  @JsonProperty public String secretAccessKey;
  @JsonProperty public String bucketName;
  @JsonProperty public boolean pathStyleAccess;
}

public class AppConfig extends Configuration {
  @JsonProperty("s3")
  public S3Config s3 = new S3Config();
}
Initialize the S3 client in your application:
S3Client s3 = S3Client.builder()
  .endpointOverride(URI.create(config.s3.endpoint))
  .region(Region.of(config.s3.region))
  .credentialsProvider(StaticCredentialsProvider.create(
      AwsBasicCredentials.create(config.s3.accessKeyId, config.s3.secretAccessKey)))
  .serviceConfiguration(S3Configuration.builder()
      .pathStyleAccessEnabled(config.s3.pathStyleAccess)
      .build())
  .build();
Run in dev mode:
java -jar target/myapp.jar server config-dev.yml

4. Prod Setup: Kubernetes & AWS S3

In production, you'll switch to using real AWS S3 and load credentials securely:

Create Kubernetes Secret and ConfigMap

kubectl create secret generic s3-secret \
  --from-literal=S3_ACCESS_KEY=prodAccessKey \
  --from-literal=S3_SECRET_KEY=prodSecretKey

kubectl create configmap s3-config \
  --from-literal=S3_BUCKET=prod-bucket \
  --from-literal=S3_REGION=us-east-1

5. Production Config: config-prod.yml

Let Dropwizard use environment variables:
server:
  applicationConnectors:
    - type: http
      port: 8080

s3:
  endpoint: ${S3_ENDPOINT}
  region: ${S3_REGION}
  accessKeyId: ${AWS_ACCESS_KEY_ID}
  secretAccessKey: ${AWS_SECRET_ACCESS_KEY}
  bucketName: ${S3_BUCKET}
  pathStyleAccess: false

6. Kubernetes Deployment Snippet

Inject config into your app:
env:
  - name: S3_ENDPOINT
    valueFrom:
      configMapKeyRef:
        name: s3-config
        key: S3_ENDPOINT
  - name: S3_REGION
    valueFrom:
      configMapKeyRef:
        name: s3-config
        key: S3_REGION
  - name: S3_BUCKET
    valueFrom:
      configMapKeyRef:
        name: s3-config
        key: S3_BUCKET
  - name: AWS_ACCESS_KEY_ID
    valueFrom:
      secretKeyRef:
        name: s3-credentials
        key: AWS_ACCESS_KEY_ID
  - name: AWS_SECRET_ACCESS_KEY
    valueFrom:
      secretKeyRef:
        name: s3-credentials
        key: AWS_SECRET_ACCESS_KEY
Launch in prod:
java -jar myapp.jar server config-prod.yml

7. Why This Setup Shines

  • Rapid local dev using MinIO via Docker
  • Secure production with AWS S3 and credentials managed through Kubernetes
  • Clean environment separation with two config files
  • Scales well while keeping your storage logic simple and portable
By following this pattern—Docker/MinIO for dev and AWS S3 with Kubernetes for production—you create a flexible, secure, and maintainable foundation for file storage in Dropwizard. Whether you’re enabling uploads, backups, or media processing, this setup scales well from your laptop to the cloud.

image quote pre code