Month: June 2024

  • Fixing ‘host must not be null’ with LocalStack and AWS S3 Client

    After being inspired by Piotr Przybyl‘s talk about integration testing, I started off a new project with some thorough testing of a Spring Boot JAR.

    Piotr Przybyl on Integration Testing

    Software development is full of obscure problems, and when uploading an object to an emulated Amazon S3 service using LocalStack, I kept getting the error:

    java.lang.NullPointerException: host must not be null.

    Not the most helpful error message, especially since I was setting endpointOverride on my S3Client builder in this way:

    this.s3Client = S3Client.builder().endpointOverride(localstack.getEndpoint()).credentialsProvider(StaticCredentialsProvider.create(credentials)).build();

    Some hours of painful searching suggested that the error message was pointing me in the wrong direction.

    The solution? Add this to the Builder:

    .forcePathStyle(Boolean.TRUE)