question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create S3 Client with endpointOverride and no Region

See original GitHub issue

Describe the Feature

I would like to be able to create a S3 client without the region if I provide the endpoint configuration.

With the V1 SDK I can create and use a client without a region when I provide the endpoint configuration.

EndpointConfiguration epc = new EndpointConfiguration("http://" + overrideHost + ":" + httpsPort, null);
    AmazonS3 s3Client = AmazonS3Client.builder().withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(ACCESS_KEY_ID, SECRET_KEY)))
        .withEndpointConfiguration(epc).withPathStyleAccessEnabled(true).build();

With the V2 SDK I get an exception:

    S3ClientBuilder builder = S3Client.builder();
    builder.credentialsProvider(
        StaticCredentialsProvider.create(AwsBasicCredentials.create(ACCESS_KEY_ID, SECRET_KEY)));
    builder.endpointOverride(URI.create("http://" + overrideHost + ":" + httpsPort));
    S3Configuration confBuilder = S3Configuration.builder().pathStyleAccessEnabled(true).build();
    builder
        .serviceConfiguration(confBuilder)
        .httpClient(
            UrlConnectionHttpClient.builder().build());

    S3Client client = builder.build();

[ERROR] Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@29caf222: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@5fcacc0: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@5b6813df: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@1d572e62: Unable to contact EC2 metadata service.]

Is your Feature Request related to a problem?

Trying to set configuration to leverage different S3 compatible data sources using this SDK.

Proposed Solution

Describe alternatives you’ve considered

Use the V1 SDK, but would like to stay on the latest. Also considered leaving a default region in there, but that makes the code more confusing as the value is meaningless when the endpoint is provided.

Additional Context

Have the requirement to be able to switch between S3 endpoints based on configuration. With the requirement of a region I will either be plugging in a dummy value that will make the code more confusing, or using the older SDK.

  • I may be able to implement this feature request

Your Environment

  • AWS Java SDK version used: 2.13.45 and 1.11.860
  • JDK version used: 1.8
  • Operating System and version: Windows and Linux

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
mpingcommented, Nov 23, 2021

I think it’s a good idea to support non-aws s3 providers, because S3 is a protocol and there are already multiple industry implementations, thus everybody wins if an SDK supports many implementations of the standard. Likewise, it would be awkward if a non-aws client library didn’t work with specifically AWS S3.

2reactions
scotty-gcommented, Nov 15, 2021

Even though using a non-AWS endpoint doesn’t seem to be officially supported by the v2 SDK based on the conversation above, we’ve been able to use it up to this point by configuring a dummy region. With a recent change in 2.17.79, this is no longer possible either as using a non-AWS region name results in a NullPointerException.

Should we update the README of this project to explicitly indicate this SDK is only usable with AWS S3?

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS region selection - AWS SDK for Java 2.x
Each AWS client can be configured to use a specific endpoint within a region by calling the endpointOverride method. For example, to configure...
Read more >
How do you configure the endpoint for Amazon S3 by using ...
Looks like you can create a URI object and pass that when you create the Service client. URI myURI = new URI("<endpoint URL>");...
Read more >
S3AccessPointBuilder (AWS Java SDK :: Services - javadoc.io
Generate an endpoint URI with no path that maps to the Access Point information stored in this builder. Methods inherited from class java.lang.Object...
Read more >
software.amazon.awssdk.services.s3.S3ClientBuilder ...
endpointOverride (URI.create(String.format("http://localhost:%d", mappedPort))) ... public static S3Client createS3Client(final Integer mappedPort) { final ...
Read more >
How can I override endpoint of S3 Client to point to local ...
URI endpointOverride = new URI("http://localhost:4566"); S3Client s3 = S3Client.builder() .endpointOverride(endpointOverride ) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found