Repository navigation
Description
Describe the bug
When building an S3Client, the client throws an SdkClientException because it was unable to load a region. However, I added an SdkPlugin to the builder which sets a region. I think this is due to the plugin being evaluated after the builder checks for a region.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
The plugin should be able to set the region, and the S3Client should build without throwing an exception.
Current Behavior
When an S3Client builds, it throws an SdkClientException due to not finding a region, even though the Plugin sets a region.
Error log:
Exception in thread "main" software.amazon.awssdk.core.exception.SdkClientException: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@60f00693: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@65c7a252: 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@1e0b4072: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@50378a4: Unable to contact EC2 metadata service.]
at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:130)
at software.amazon.awssdk.regions.providers.AwsRegionProviderChain.getRegion(AwsRegionProviderChain.java:70)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.resolveRegion(AwsDefaultClientBuilder.java:375)
at software.amazon.awssdk.utils.AttributeMap$DerivedValue.primeCache(AttributeMap.java:604)
at software.amazon.awssdk.utils.AttributeMap$DerivedValue.get(AttributeMap.java:593)
at software.amazon.awssdk.utils.AttributeMap$Builder.resolveValue(AttributeMap.java:400)
at software.amazon.awssdk.utils.AttributeMap$Builder.internalGet(AttributeMap.java:389)
at software.amazon.awssdk.utils.AttributeMap$Builder.access$1300(AttributeMap.java:201)
at software.amazon.awssdk.utils.AttributeMap$Builder$1.get(AttributeMap.java:403)
at software.amazon.awssdk.services.s3.DefaultS3BaseClientBuilder.lambda$finalizeServiceConfiguration$2(DefaultS3BaseClientBuilder.java:222)
at software.amazon.awssdk.utils.AttributeMap$DerivedValue.primeCache(AttributeMap.java:604)
at software.amazon.awssdk.utils.AttributeMap$DerivedValue.get(AttributeMap.java:593)
at software.amazon.awssdk.utils.AttributeMap$Builder.resolveValue(AttributeMap.java:400)
at software.amazon.awssdk.utils.AttributeMap$Builder.internalComputeIfAbsent(AttributeMap.java:331)
at software.amazon.awssdk.utils.AttributeMap$Builder.putLazyIfAbsent(AttributeMap.java:275)
at software.amazon.awssdk.core.client.config.SdkClientConfiguration$Builder.lazyOptionIfAbsent(SdkClientConfiguration.java:182)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.finalizeAwsConfiguration(AwsDefaultClientBuilder.java:191)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.finalizeChildConfiguration(AwsDefaultClientBuilder.java:173)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.syncClientConfiguration(SdkDefaultClientBuilder.java:206)
at software.amazon.awssdk.services.s3.DefaultS3ClientBuilder.buildClient(DefaultS3ClientBuilder.java:37)
at software.amazon.awssdk.services.s3.DefaultS3ClientBuilder.buildClient(DefaultS3ClientBuilder.java:26)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.build(SdkDefaultClientBuilder.java:173)
at org.example.App.main(App.java:16)
Reproduction Steps
package org.example;
import java.net.URI;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3ServiceClientConfiguration;
public class App {
public static void main(String[] args) {
S3Client client = S3Client.builder()
.addPlugin(config -> {
((S3ServiceClientConfiguration.Builder) config)
.region(Region.US_EAST_1);
})
.build();
}
}Possible Solution
I think that the builder is reading the region before running plugins, which causes the exception to be thrown.
Additional Information/Context
No response
AWS Java SDK version used
software.amazon.awssdk:s3:2.47.4
JDK version used
openjdk 26.0.1 2026-04-21 OpenJDK Runtime Environment Temurin-26.0.1+8 (build 26.0.1+8) OpenJDK 64-Bit Server VM Temurin-26.0.1+8 (build 26.0.1+8, mixed mode, sharing)
Operating System and version
Microsoft Windows 11 Enterprise 10.0.26100 Build 26100
Activity
Techno3d commentedon Jul 15, 2026
I may have accidentally checked the regression checkbox. I do not this is a regression, my bad.
bhoradc commentedon Jul 15, 2026
@Techno3d - Noted, thanks for reporting this.
Your analysis appears to be correct, the SDK resolves region during client finalization, which occurs before plugins are invoked. Since no region is available through the builder or the default provider chain at that point, the build fails before your plugin gets a chance to set it.
Note that plugins do currently override region if it's already resolvable, so the plugin mechanism itself works, it's just that the SDK needs a value to be present before plugins execute.
In the meantime, you can work around this by setting region outside of the
SdkPlugin. I will review this with the team to determine next steps. Thanks!Techno3d commentedon Jul 17, 2026
Thanks for getting back so quickly. Would it be okay for me to work on the fix for this and submit a PR?
Techno3d commentedon Jul 17, 2026
I was looking through the code, and found something a bit strange in how the client configuration gets finalized. In
SdkDefaultClientBuilder::syncClientConfigurationand the async version, the method passesSdkClientConfigurationto all of the methods it calls (e.g.setOverrides(),mergeChildDefaults(), etc). Each of these methods takes theSdkClientConfiguration, and converts them to a Builder before building and returning. Is there a reason that the methods useSdkClientConfigurationinstead ofBuilders, and then syncClientConfiguration callsbuild()at the end?I think using builders would solve this issue of the region being resolved before the plugins gets to run, but preserves the plugins precedence. Though there might be something I'm missing.
Techno3d commentedon Jul 17, 2026
I think this code change might fix the issue, though I'm not certain if the finalizeConfiguration methods could overwrite something that plugins could set. My previous comment might be helpful, but I think I was overthinking things a little.