Configure java AWS sdk client to write to local S3 bucket (localstack)

Viewed 8032

So i am able to configure a local s3 bucket using localstack with the following command

aws --endpoint-url=http://localhost:4572 s3 mb s3://mytestbucket

How am I able to change the configuration for the java AWS SDK in order to write/read from/to this bucket instead of remote aws s3?

I have looked at the configuration but not able to find any tangible

2 Answers

This is done via the endpoint configuration within the AWS S3 SDK when creating the client. For example:

final AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration(s3Endpoint, REGION);
        final AmazonS3 client = AmazonS3ClientBuilder.standard()
            .withEndpointConfiguration(endpoint)
            .build();

The endpoint can be a string like http://localhost:4572 (where the port number needs to be whatever port s3 in localstack is listening on - by default 4572)

Related