Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 640
L-Samuels Avatar asked Oct 26 '18 16:10

L-Samuels


People also ask

How do I access an S3 bucket from AWS SDK?

To access Amazon Simple Storage Service, create an AWS. S3 service object. Call the listBuckets method of the Amazon S3 service object to retrieve a list of your buckets. The data parameter of the callback function has a Buckets property containing an array of maps to represent the buckets.

Can you interface with AWS using Java SDK?

Develop and deploy applications with the AWS SDK for Java. The SDK makes it easy to call AWS services using idiomatic Java APIs.


1 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)

like image 156
David Avatar answered Oct 12 '22 12:10

David