Skip to content

Remove ServiceMetadata usage from AwsClientEndpointProvider in generated client builders#7094

Open
S-Saranya1 wants to merge 3 commits into
feature/master/remove-service-metadata-usagefrom
somepal/client-endpoint-provider-remove-servicemetadata
Open

Remove ServiceMetadata usage from AwsClientEndpointProvider in generated client builders#7094
S-Saranya1 wants to merge 3 commits into
feature/master/remove-service-metadata-usagefrom
somepal/client-endpoint-provider-remove-servicemetadata

Conversation

@S-Saranya1

@S-Saranya1 S-Saranya1 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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

  • Added buildIfOverridePresent() method to the Builder. This checks only endpoint overrides and environment sources (system properties, env vars, profile config) and returns Optional.empty() if none are configured, without ever touching ServiceMetadata.
  • Added resolveFromOverridesAndEnvironment() — same resolution chain as existing resolveClientEndpoint() but without the ServiceMetadata fallback.

BaseClientBuilderClass.java (codegen template)

  • Changed the generated finalizeServiceConfiguration() method to use a three-step approach:

    1. Call buildIfOverridePresent() — if the user configured an override or environment endpoint, use it directly.
    2. Best-effort resolve using the service's own Endpoints 2.0 provider with client-config params (region, fips, dualstack). This succeeds for 95%+ of services and produces a real, debuggable endpoint.
    3. If Endpoints 2.0 resolution fails (e.g., S3 requires request-bound params like bucket, forcePathStyle), fall back to a https://localhost placeholder that gets replaced at request time.
  • 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

  • Added unit tests for buildIfOverridePresent() covering override path, environment path, and empty result when no override is configured.
  • Verified existing endpoint resolution and invalid region validation tests continue to pass.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@S-Saranya1 S-Saranya1 requested a review from a team as a code owner June 30, 2026 22:51
@S-Saranya1 S-Saranya1 changed the title Remove ServiceMetadata usage from AwsClientEndpointProvider in genrated client builders Remove ServiceMetadata usage from AwsClientEndpointProvider in generated client builders Jul 1, 2026
@S-Saranya1 S-Saranya1 changed the base branch from master to feature/master/remove-service-metadata-usage July 1, 2026 17:06

@dagnir dagnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you mean "that will be replaced"?

return Optional.empty();
}
return Optional.of(provider);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants