Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import software.amazon.awssdk.awscore.client.config.AwsAdvancedClientOption;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.awscore.defaultsmode.DefaultsMode;
import software.amazon.awssdk.awscore.endpoint.AwsClientEndpointProvider;
import software.amazon.awssdk.awscore.endpoint.DualstackEnabledProvider;
import software.amazon.awssdk.awscore.endpoint.FipsEnabledProvider;
import software.amazon.awssdk.awscore.eventstream.EventStreamInitialRequestInterceptor;
Expand Down Expand Up @@ -75,6 +74,7 @@
import software.amazon.awssdk.utils.Logger;
import software.amazon.awssdk.utils.Pair;
import software.amazon.awssdk.utils.StringUtils;
import software.amazon.awssdk.utils.Validate;

/**
* An SDK-internal implementation of the methods in {@link AwsClientBuilder}, {@link AwsAsyncClientBuilder} and
Expand All @@ -97,7 +97,6 @@ public abstract class AwsDefaultClientBuilder<BuilderT extends AwsClientBuilder<
extends SdkDefaultClientBuilder<BuilderT, ClientT>
implements AwsClientBuilder<BuilderT, ClientT> {
private static final Logger log = Logger.loggerFor(AwsClientBuilder.class);
private static final String DEFAULT_ENDPOINT_PROTOCOL = "https";
private static final String[] FIPS_SEARCH = {"fips-", "-fips"};
private static final String[] FIPS_REPLACE = {"", ""};

Expand Down Expand Up @@ -188,7 +187,6 @@ private SdkClientConfiguration finalizeAwsConfiguration(SdkClientConfiguration c
this::resolveCredentialsIdentityProvider)
// Set CREDENTIALS_PROVIDER, because older clients may be relying on it
.lazyOptionIfAbsent(AwsClientOption.CREDENTIALS_PROVIDER, this::resolveCredentialsProvider)
.lazyOptionIfAbsent(SdkClientOption.CLIENT_ENDPOINT_PROVIDER, this::resolveClientEndpointProvider)
// Set ENDPOINT and ENDPOINT_OVERRIDDEN, because older clients may be relying on it
.lazyOptionIfAbsent(SdkClientOption.ENDPOINT, this::resolveEndpoint)
.lazyOptionIfAbsent(SdkClientOption.ENDPOINT_OVERRIDDEN, this::resolveEndpointOverridden)
Expand Down Expand Up @@ -320,41 +318,29 @@ private Region resolveSigningRegion(LazyValueSource config) {
.signingRegion(config.get(AwsClientOption.AWS_REGION));
}

/**
* Specify the client endpoint provider to use for the client, if the client didn't specify one itself.
* <p>
* This is only used for older client versions. Newer clients specify this value themselves.
*/
private ClientEndpointProvider resolveClientEndpointProvider(LazyValueSource config) {
ServiceMetadataAdvancedOption<String> useGlobalS3EndpointProperty =
ServiceMetadataAdvancedOption.DEFAULT_S3_US_EAST_1_REGIONAL_ENDPOINT;
return AwsClientEndpointProvider.builder()
.serviceEndpointPrefix(serviceEndpointPrefix())
.defaultProtocol(DEFAULT_ENDPOINT_PROTOCOL)
.region(config.get(AwsClientOption.AWS_REGION))
.profileFile(config.get(SdkClientOption.PROFILE_FILE_SUPPLIER))
.profileName(config.get(SdkClientOption.PROFILE_NAME))
.putAdvancedOption(useGlobalS3EndpointProperty,
config.get(useGlobalS3EndpointProperty))
.dualstackEnabled(config.get(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED))
.fipsEnabled(config.get(AwsClientOption.FIPS_ENDPOINT_ENABLED))
.build();
}

/**
* Resolve the client endpoint. This code is only needed by old SDK client versions. Newer SDK client versions resolve this
* information from the client endpoint provider.
*/
private URI resolveEndpoint(LazyValueSource config) {
return config.get(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).clientEndpoint();
return requireClientEndpointProvider(config).clientEndpoint();
}

/**
* Resolve whether the endpoint was overridden by the customer. This code is only needed by old SDK client versions. Newer SDK
* client versions resolve this information from the client endpoint provider.
*/
private boolean resolveEndpointOverridden(LazyValueSource config) {
return config.get(SdkClientOption.CLIENT_ENDPOINT_PROVIDER).isEndpointOverridden();
return requireClientEndpointProvider(config).isEndpointOverridden();
}

private ClientEndpointProvider requireClientEndpointProvider(LazyValueSource config) {
ClientEndpointProvider clientEndpointProvider = config.get(SdkClientOption.CLIENT_ENDPOINT_PROVIDER);
Validate.notNull(clientEndpointProvider,
"No CLIENT_ENDPOINT_PROVIDER was configured. This is typically caused by using "
+ "an older service client version with a newer sdk-core. "
+ "Please align all SDK dependency versions.");
return clientEndpointProvider;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ public <T> Builder putAdvancedOption(ServiceMetadataAdvancedOption<T> option, T
return this;
}

/**
* @deprecated Since 2.x.x. Use {@link #resolveFromOverrides()} instead, combined with the service's

@S-Saranya1 S-Saranya1 Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update the 2.x.x to actual version before merging to master.

* EndpointProvider for default endpoint resolution. This method triggers expensive
* {@code ServiceMetadata} initialization which is unnecessary when the service
* EndpointProvider can resolve the default endpoint directly.
*/
@Deprecated
public AwsClientEndpointProvider build() {
return new AwsClientEndpointProvider(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.ClientEndpointProvider;
import software.amazon.awssdk.core.internal.retry.SdkDefaultRetryStrategy;
import software.amazon.awssdk.core.signer.Signer;
import software.amazon.awssdk.http.SdkHttpClient;
Expand Down Expand Up @@ -403,6 +404,17 @@ protected TestClient buildClient() {
return new TestClient(super.syncClientConfiguration());
}

@Override
protected SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
return config.toBuilder()
.lazyOptionIfAbsent(SdkClientOption.CLIENT_ENDPOINT_PROVIDER, c -> {
URI endpoint = URI.create("https://" + serviceEndpointPrefix() + "."
+ c.get(AwsClientOption.AWS_REGION) + ".amazonaws.com");
return ClientEndpointProvider.create(endpoint, false);
})
.build();
}

@Override
protected String serviceEndpointPrefix() {
return ENDPOINT_PREFIX;
Expand Down Expand Up @@ -444,6 +456,17 @@ protected TestAsyncClient buildClient() {
return new TestAsyncClient(super.asyncClientConfiguration());
}

@Override
protected SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
return config.toBuilder()
.lazyOptionIfAbsent(SdkClientOption.CLIENT_ENDPOINT_PROVIDER, c -> {
URI endpoint = URI.create("https://" + serviceEndpointPrefix() + "."
+ c.get(AwsClientOption.AWS_REGION) + ".amazonaws.com");
return ClientEndpointProvider.create(endpoint, false);
})
.build();
}

@Override
protected String serviceEndpointPrefix() {
return ENDPOINT_PREFIX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
import software.amazon.awssdk.awscore.internal.defaultsmode.DefaultsModeConfiguration;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.ClientEndpointProvider;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import java.net.URI;
import software.amazon.awssdk.core.internal.retry.SdkDefaultRetryStrategy;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.http.SdkHttpClient;
Expand Down Expand Up @@ -187,6 +191,17 @@ protected TestClient buildClient() {
return new TestClient(super.syncClientConfiguration());
}

@Override
protected SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
return config.toBuilder()
.lazyOptionIfAbsent(SdkClientOption.CLIENT_ENDPOINT_PROVIDER, c -> {
URI endpoint = URI.create("https://" + serviceEndpointPrefix() + "."
+ c.get(AwsClientOption.AWS_REGION) + ".amazonaws.com");
return ClientEndpointProvider.create(endpoint, false);
})
.build();
}

@Override
protected String serviceEndpointPrefix() {
return ENDPOINT_PREFIX;
Expand Down Expand Up @@ -220,6 +235,17 @@ protected TestAsyncClient buildClient() {
return new TestAsyncClient(super.asyncClientConfiguration());
}

@Override
protected SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
return config.toBuilder()
.lazyOptionIfAbsent(SdkClientOption.CLIENT_ENDPOINT_PROVIDER, c -> {
URI endpoint = URI.create("https://" + serviceEndpointPrefix() + "."
+ c.get(AwsClientOption.AWS_REGION) + ".amazonaws.com");
return ClientEndpointProvider.create(endpoint, false);
})
.build();
}

@Override
protected String serviceEndpointPrefix() {
return ENDPOINT_PREFIX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static software.amazon.awssdk.awscore.client.config.AwsAdvancedClientOption.ENABLE_DEFAULT_REGION_DETECTION;
import static software.amazon.awssdk.core.client.config.SdkAdvancedClientOption.SIGNER;

import java.net.URI;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,8 +31,10 @@
import org.junit.jupiter.params.provider.MethodSource;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.core.ClientEndpointProvider;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.signer.Signer;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
Expand Down Expand Up @@ -122,6 +125,17 @@ protected TestClient buildClient() {
return new TestClient(super.syncClientConfiguration());
}

@Override
protected SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
return config.toBuilder()
.lazyOptionIfAbsent(SdkClientOption.CLIENT_ENDPOINT_PROVIDER, c -> {
URI endpoint = URI.create("https://" + serviceEndpointPrefix() + "."
+ c.get(AwsClientOption.AWS_REGION) + ".amazonaws.com");
return ClientEndpointProvider.create(endpoint, false);
})
.build();
}

@Override
protected String serviceEndpointPrefix() {
return ENDPOINT_PREFIX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import software.amazon.awssdk.core.SdkSystemSetting;
import java.net.URI;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.core.ClientEndpointProvider;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.http.SdkHttpClient;
Expand Down Expand Up @@ -159,5 +162,16 @@ protected TestClient buildClient() {

return new TestClient(config);
}

@Override
protected SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
return config.toBuilder()
.lazyOptionIfAbsent(SdkClientOption.CLIENT_ENDPOINT_PROVIDER, c -> {
URI endpoint = URI.create("https://" + serviceEndpointPrefix() + "."
+ c.get(AwsClientOption.AWS_REGION) + ".amazonaws.com");
return ClientEndpointProvider.create(endpoint, false);
})
.build();
}
}
}
2 changes: 1 addition & 1 deletion test/old-client-version-compatibility-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.20.136</version> <!-- Pre-SRA version -->
<version>2.28.1</version>
</dependency>

<!-- Test Dependencies -->
Expand Down
Loading