Remove ServiceMetadata usage from AwsClientEndpointProvider in generated client builders#7094
Conversation
…ated client builders
dagnir
left a comment
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?
| return Optional.empty(); | ||
| } | ||
| return Optional.of(provider); | ||
| } |
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?
There was a problem hiding this comment.
yeah, the resolution methods (clientEndpointFromClientOverride, etc.) were instance methods, so the Builder couldn't call them directly, hence the workaround of constructing a full provider. Agreed it's unnecessary. Made those methods static (they never used instance state anyway) and added resolveFromOverrides() method to return the endpoint resolved from the overrides.
| endpointParams)); | ||
| clientEndpointUri = endpoint.url(); | ||
| } catch (SdkClientException e) { | ||
| // Endpoint resolution failed. This is expected for services that require request-bound |
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"?
There was a problem hiding this comment.
Right, updated it.
Added the test. |
a3a5cf3
into
feature/master/remove-service-metadata-usage
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |
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