aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.2k stars 853 forks source link

Add support for service-specific endpoint overrides without code changes. #5562

Closed millems closed 2 months ago

millems commented 2 months ago

This adds support for this feature: https://docs.aws.amazon.com/sdkref/latest/guide/feature-ss-endpoints.html

The commit has been broken up into 6 commits, to hopefully simplify the code review:

Commit 1 - Made protected API changes in support of service-specific endpoint overrides.

This introduces new ClientEndpointProvider abstraction, which is used by clients to resolve the "default" endpoint for the client. The main implementation is the new AwsClientEndpointProvider class, which checks the client-level endpoint override, environment variables, system properties and profile properties, in priority order. More information about what it checks is documented here.

Other Protected API changes:

Commit 2 - Wires up the new AwsClientEndpointProvider for service clients

In this change, service client builders set the AwsClientEndpointProvider when they are created. This allows setting the service-specific environment variables, system settings and profile properties.

We also update the default AWS client builder to set the ClientEndpointProvider, so that old client versions get the new CLIENT_ENDPOINT_PROVIDER option set. The default SDK client builder is also updated to use the new provider abstraction for endpoint overrides.

This also includes EndpointSharedConfigTest, which tests to make sure that the new ways of overriding the endpoint work for clients.

Commit 3 - Wire up the new AwsClientEndpointProvider for non-clients

We want the new feature to work for other places that endpoints are derived. This commit includes updating S3Utilities, S3Presigner and PollyPresigner to also support the new way of specifying endpoint overrides.

We also update RdsPresignInterceptors in RDS, Neptune and DocDB to use the new AwsClientEndpointProvider. Here, we don't wire up support for the new environment-based endpoint overrides, because the endpoint in the presigned URL for these APIs needs to be the actual RDS endpoint URL, not overrides.

Commit 4 - Move users of the old SdkClientOptions and SdkExecutionAttributes over to the new settings

These changes are less interesting, and a bit tedious. In this, we change everywhere in the SDK that is using the old SdkClientOption.ENDPOINT, SdkClientOption.ENDPOINT_OVERRIDDEN to the new SdkClientOption.CLIENT_ENDPOINT_PROVIDER. We also update everywhere in the SDK we're using the old SdkExecutionAttribute.CLIENT_ENDPOINT and SdkClientOption.ENDPOINT_OVERRIDDEN to the new SdkInternalExecutionAttribute.CLIENT_ENDPOINT_PROVIDER.

Commit 5 - CodeGen test updates

These are even less interesting. These are the codegen test files we changed in support of commit 2 above.

Commit 6 - Changelog Entry

Self-explanatory.

stantonk commented 2 months ago

So excited for this!!

sonarcloud[bot] commented 2 months ago

Quality Gate Failed Quality Gate failed

Failed conditions
79.7% Coverage on New Code (required ≥ 80%)
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint