Remove ServiceMetadata usage from AwsClientEndpointProvider in generated client builders#7094
Open
S-Saranya1 wants to merge 3 commits into
Conversation
…ated client builders
dagnir
reviewed
Jul 1, 2026
dagnir
left a comment
Contributor
There was a problem hiding this comment.
Can we add or update tests in codegen-generated-classes-test to test this behavior on a generated client?
| .addCode(" } catch ($T e) {\n", | ||
| ClassName.get("software.amazon.awssdk.core.exception", "SdkClientException")) | ||
| .addCode(" // Endpoint resolution failed. This is expected for services that require request-bound\n") | ||
| .addCode(" // params (e.g., S3 bucket). Use a placeholder that will be resolved at request time.\n") |
Contributor
There was a problem hiding this comment.
Do you mean "that will be replaced"?
| return Optional.empty(); | ||
| } | ||
| return Optional.of(provider); | ||
| } |
Contributor
There was a problem hiding this comment.
This is a pretty awkward API. Can we just introduce a method that only returns the endpoint resolved from the overrides, and the client builders can check that instead?
| endpointParams)); | ||
| clientEndpointUri = endpoint.url(); | ||
| } catch (SdkClientException e) { | ||
| // Endpoint resolution failed. This is expected for services that require request-bound |
Contributor
There was a problem hiding this comment.
This is expected for services that require request-bound
Is this always accurate? (i.e. could the params be from somewhere other than request bound (e.g. context params). Should we just say "expected for services with required parameters besides region/dualstack/fips"?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
When creating any AWS service client (e.g., DynamoDbClient.builder().region(...).build()), the SDK resolves a default client endpoint by calling ServiceMetadata.of(servicePrefix). This triggers the static initialization of GeneratedServiceMetadataProvider, which eagerly instantiates all 310 service metadata classes — even though only one is needed. This adds 350-500ms of cold start latency, significantly impacting Lambda and other latency-sensitive
applications.
The endpoint resolved by ServiceMetadata is ultimately replaced by Endpoints 2.0 at request time anyway, making this initialization cost entirely wasted.
Modifications
AwsClientEndpointProvider.java
BaseClientBuilderClass.java (codegen template)
Changed the generated finalizeServiceConfiguration() method to use a three-step approach:
Added host validation after successful resolution to preserve fail-fast behavior for invalid regions (e.g., US_EAST_1 with underscores).
useDualStack/useFips params are only set conditionally based on whether the service's endpoint rules model declares those built-ins.
Testing
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License