diff --git a/.changes/05ac561b-963f-4953-bb4f-1fc19fc1207c.json b/.changes/05ac561b-963f-4953-bb4f-1fc19fc1207c.json new file mode 100644 index 00000000000..9465e61b9fe --- /dev/null +++ b/.changes/05ac561b-963f-4953-bb4f-1fc19fc1207c.json @@ -0,0 +1,8 @@ +{ + "id": "05ac561b-963f-4953-bb4f-1fc19fc1207c", + "type": "feature", + "description": "Add `regionProvider` property to client config", + "issues": [ + "awslabs/aws-sdk-kotlin#1478" + ] +} \ No newline at end of file diff --git a/aws-runtime/aws-config/api/aws-config.api b/aws-runtime/aws-config/api/aws-config.api index 05589280306..ffc00b119f1 100644 --- a/aws-runtime/aws-config/api/aws-config.api +++ b/aws-runtime/aws-config/api/aws-config.api @@ -222,6 +222,27 @@ public abstract class aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory public static synthetic fun fromEnvironment$default (Laws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; } +public abstract interface class aws/sdk/kotlin/runtime/config/AwsSdkClientConfig : aws/smithy/kotlin/runtime/client/SdkClientConfig { + public abstract fun getApplicationId ()Ljava/lang/String; + public abstract fun getRegion ()Ljava/lang/String; + public abstract fun getRegionProvider ()Laws/smithy/kotlin/runtime/client/region/RegionProvider; + public abstract fun getUseDualStack ()Z + public abstract fun getUseFips ()Z +} + +public abstract interface class aws/sdk/kotlin/runtime/config/AwsSdkClientConfig$Builder { + public abstract fun getApplicationId ()Ljava/lang/String; + public abstract fun getRegion ()Ljava/lang/String; + public abstract fun getRegionProvider ()Laws/smithy/kotlin/runtime/client/region/RegionProvider; + public abstract fun getUseDualStack ()Ljava/lang/Boolean; + public abstract fun getUseFips ()Ljava/lang/Boolean; + public abstract fun setApplicationId (Ljava/lang/String;)V + public abstract fun setRegion (Ljava/lang/String;)V + public abstract fun setRegionProvider (Laws/smithy/kotlin/runtime/client/region/RegionProvider;)V + public abstract fun setUseDualStack (Ljava/lang/Boolean;)V + public abstract fun setUseFips (Ljava/lang/Boolean;)V +} + public final class aws/sdk/kotlin/runtime/config/AwsSdkSetting { public static final field INSTANCE Laws/sdk/kotlin/runtime/config/AwsSdkSetting; public final fun getAwsAccessKeyId ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting; @@ -512,21 +533,21 @@ public final class aws/sdk/kotlin/runtime/config/useragent/ResolveUserAgentKt { public static synthetic fun resolveUserAgentAppId$default (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; } -public final class aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain : aws/sdk/kotlin/runtime/region/RegionProviderChain, aws/sdk/kotlin/runtime/region/RegionProvider, java/io/Closeable { +public final class aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain : aws/sdk/kotlin/runtime/region/RegionProviderChain, aws/smithy/kotlin/runtime/client/region/RegionProvider, java/io/Closeable { public fun ()V public fun (Laws/smithy/kotlin/runtime/util/PlatformProvider;Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;)V public synthetic fun (Laws/smithy/kotlin/runtime/util/PlatformProvider;Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun close ()V } -public final class aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider : aws/sdk/kotlin/runtime/region/RegionProvider { +public final class aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider : aws/smithy/kotlin/runtime/client/region/RegionProvider { public fun ()V public fun (Laws/smithy/kotlin/runtime/util/EnvironmentProvider;)V public synthetic fun (Laws/smithy/kotlin/runtime/util/EnvironmentProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class aws/sdk/kotlin/runtime/region/ImdsRegionProvider : aws/sdk/kotlin/runtime/region/RegionProvider, java/io/Closeable { +public final class aws/sdk/kotlin/runtime/region/ImdsRegionProvider : aws/smithy/kotlin/runtime/client/region/RegionProvider, java/io/Closeable { public fun ()V public fun (Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/PlatformEnvironProvider;)V public synthetic fun (Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/PlatformEnvironProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -534,14 +555,14 @@ public final class aws/sdk/kotlin/runtime/region/ImdsRegionProvider : aws/sdk/ko public fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider : aws/sdk/kotlin/runtime/region/RegionProvider { +public final class aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider : aws/smithy/kotlin/runtime/client/region/RegionProvider { public fun ()V public fun (Laws/smithy/kotlin/runtime/util/PropertyProvider;)V public synthetic fun (Laws/smithy/kotlin/runtime/util/PropertyProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class aws/sdk/kotlin/runtime/region/ProfileRegionProvider : aws/sdk/kotlin/runtime/region/RegionProvider { +public final class aws/sdk/kotlin/runtime/region/ProfileRegionProvider : aws/smithy/kotlin/runtime/client/region/RegionProvider { public fun ()V public fun (Laws/smithy/kotlin/runtime/util/LazyAsyncValue;)V public synthetic fun (Laws/smithy/kotlin/runtime/util/LazyAsyncValue;ILkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -549,14 +570,10 @@ public final class aws/sdk/kotlin/runtime/region/ProfileRegionProvider : aws/sdk public fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public abstract interface class aws/sdk/kotlin/runtime/region/RegionProvider { - public abstract fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public class aws/sdk/kotlin/runtime/region/RegionProviderChain : aws/sdk/kotlin/runtime/region/RegionProvider { +public class aws/sdk/kotlin/runtime/region/RegionProviderChain : aws/smithy/kotlin/runtime/client/region/RegionProvider { public fun (Ljava/util/List;)V - public fun ([Laws/sdk/kotlin/runtime/region/RegionProvider;)V - protected final fun getProviders ()[Laws/sdk/kotlin/runtime/region/RegionProvider; + public fun ([Laws/smithy/kotlin/runtime/client/region/RegionProvider;)V + protected final fun getProviders ()[Laws/smithy/kotlin/runtime/client/region/RegionProvider; public fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; } diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory.kt index ed5f4b0cd99..2832b08c71c 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory.kt @@ -5,7 +5,6 @@ package aws.sdk.kotlin.runtime.config -import aws.sdk.kotlin.runtime.client.AwsSdkClientConfig import aws.sdk.kotlin.runtime.config.compression.resolveDisableRequestCompression import aws.sdk.kotlin.runtime.config.compression.resolveRequestMinCompressionSizeBytes import aws.sdk.kotlin.runtime.config.endpoints.resolveUseDualStack @@ -74,7 +73,7 @@ public abstract class AbstractAwsSdkClientFactory< block?.let(config::apply) config.logMode = config.logMode ?: ClientSettings.LogMode.resolve(platform = platform) - config.region = config.region ?: resolveRegion(profile = profile) + config.region = config.region ?: config.regionProvider?.getRegion() ?: resolveRegion(profile = profile) config.useFips = config.useFips ?: resolveUseFips(profile = profile) config.useDualStack = config.useDualStack ?: resolveUseDualStack(profile = profile) config.applicationId = config.applicationId ?: resolveUserAgentAppId(platform, profile) diff --git a/aws-runtime/aws-core/common/src/aws/sdk/kotlin/runtime/client/AwsSdkClientConfig.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AwsSdkClientConfig.kt similarity index 75% rename from aws-runtime/aws-core/common/src/aws/sdk/kotlin/runtime/client/AwsSdkClientConfig.kt rename to aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AwsSdkClientConfig.kt index b8073748e0e..dfd717c1e8e 100644 --- a/aws-runtime/aws-core/common/src/aws/sdk/kotlin/runtime/client/AwsSdkClientConfig.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AwsSdkClientConfig.kt @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.runtime.client +package aws.sdk.kotlin.runtime.config import aws.smithy.kotlin.runtime.client.SdkClientConfig +import aws.smithy.kotlin.runtime.client.region.RegionProvider /** * Base interface all generated AWS SDK Kotlin clients implement @@ -19,6 +20,17 @@ public interface AwsSdkClientConfig : SdkClientConfig { */ public val region: String? + /** + * An optional region provider that determines the AWS region for client operations. When specified, this provider + * takes precedence over the default region provider chain, unless a static region is explicitly configured. + * + * Region Resolution Priority: + * 1. Static region (if specified) + * 2. Custom region provider (if configured) + * 3. Default region provider chain + */ + public val regionProvider: RegionProvider? + /** * Flag to toggle whether to use [FIPS](https://aws.amazon.com/compliance/fips/) endpoints when making requests. * Disabled by default. @@ -54,6 +66,17 @@ public interface AwsSdkClientConfig : SdkClientConfig { */ public var region: String? + /** + * An optional region provider that determines the AWS region for client operations. When specified, this provider + * takes precedence over the default region provider chain, unless a static region is explicitly configured. + * + * Region Resolution Priority: + * 1. Static region (if specified) + * 2. Custom region provider (if configured) + * 3. Default region provider chain + */ + public var regionProvider: RegionProvider? + /** * Flag to toggle whether to use [FIPS](https://aws.amazon.com/compliance/fips/) endpoints when making requests. * Disabled by default. diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain.kt index 25d59284b6c..5ac84815606 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain.kt @@ -9,6 +9,7 @@ import aws.sdk.kotlin.runtime.config.imds.ImdsClient import aws.sdk.kotlin.runtime.config.imds.InstanceMetadataProvider import aws.sdk.kotlin.runtime.config.profile.AwsProfile import aws.sdk.kotlin.runtime.config.profile.loadAwsSharedConfig +import aws.smithy.kotlin.runtime.client.region.RegionProvider import aws.smithy.kotlin.runtime.io.Closeable import aws.smithy.kotlin.runtime.util.LazyAsyncValue import aws.smithy.kotlin.runtime.util.PlatformProvider diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider.kt index c1058296510..126083ebf4e 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider.kt @@ -6,6 +6,7 @@ package aws.sdk.kotlin.runtime.region import aws.sdk.kotlin.runtime.config.AwsSdkSetting +import aws.smithy.kotlin.runtime.client.region.RegionProvider import aws.smithy.kotlin.runtime.util.EnvironmentProvider import aws.smithy.kotlin.runtime.util.PlatformProvider diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ImdsRegionProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ImdsRegionProvider.kt index 6b488006617..9191b9957df 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ImdsRegionProvider.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ImdsRegionProvider.kt @@ -8,6 +8,7 @@ package aws.sdk.kotlin.runtime.region import aws.sdk.kotlin.runtime.config.AwsSdkSetting import aws.sdk.kotlin.runtime.config.imds.ImdsClient import aws.sdk.kotlin.runtime.config.imds.InstanceMetadataProvider +import aws.smithy.kotlin.runtime.client.region.RegionProvider import aws.smithy.kotlin.runtime.config.resolve import aws.smithy.kotlin.runtime.io.Closeable import aws.smithy.kotlin.runtime.util.PlatformEnvironProvider diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ProfileRegionProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ProfileRegionProvider.kt index 9e50d845d7b..c1b4491354b 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ProfileRegionProvider.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ProfileRegionProvider.kt @@ -8,6 +8,7 @@ package aws.sdk.kotlin.runtime.region import aws.sdk.kotlin.runtime.config.profile.AwsProfile import aws.sdk.kotlin.runtime.config.profile.loadAwsSharedConfig import aws.sdk.kotlin.runtime.config.profile.region +import aws.smithy.kotlin.runtime.client.region.RegionProvider import aws.smithy.kotlin.runtime.util.LazyAsyncValue import aws.smithy.kotlin.runtime.util.PlatformProvider import aws.smithy.kotlin.runtime.util.asyncLazy diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/RegionProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/RegionProvider.kt deleted file mode 100644 index 63105bdf3c9..00000000000 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/RegionProvider.kt +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package aws.sdk.kotlin.runtime.region - -/** - * Interface for providing AWS region information. Implementations are free to use any strategy for - * providing region information - */ -public interface RegionProvider { - /** - * Return the region name to use. If region information is not available, implementations should return null - */ - public suspend fun getRegion(): String? -} diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/RegionProviderChain.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/RegionProviderChain.kt index 4f7c4ce3012..431d8267533 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/RegionProviderChain.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/RegionProviderChain.kt @@ -5,6 +5,7 @@ package aws.sdk.kotlin.runtime.region +import aws.smithy.kotlin.runtime.client.region.RegionProvider import aws.smithy.kotlin.runtime.telemetry.logging.logger import aws.smithy.kotlin.runtime.util.asyncLazy import kotlin.coroutines.coroutineContext diff --git a/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/region/AwsRegionProviderChainTest.kt b/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/region/AwsRegionProviderChainTest.kt index 495e715184f..a1ccc199da0 100644 --- a/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/region/AwsRegionProviderChainTest.kt +++ b/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/region/AwsRegionProviderChainTest.kt @@ -5,6 +5,7 @@ package aws.sdk.kotlin.runtime.region +import aws.smithy.kotlin.runtime.client.region.RegionProvider import kotlinx.coroutines.test.runTest import kotlin.test.Test import kotlin.test.assertEquals diff --git a/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainJVM.kt b/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainJVM.kt index b581deb1d18..aae8855d4ea 100644 --- a/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainJVM.kt +++ b/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainJVM.kt @@ -7,6 +7,7 @@ package aws.sdk.kotlin.runtime.region import aws.sdk.kotlin.runtime.config.imds.InstanceMetadataProvider import aws.sdk.kotlin.runtime.config.profile.AwsProfile +import aws.smithy.kotlin.runtime.client.region.RegionProvider import aws.smithy.kotlin.runtime.io.Closeable import aws.smithy.kotlin.runtime.util.LazyAsyncValue import aws.smithy.kotlin.runtime.util.PlatformProvider diff --git a/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider.kt b/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider.kt index e2be63a151a..e992035cca5 100644 --- a/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider.kt +++ b/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider.kt @@ -6,6 +6,7 @@ package aws.sdk.kotlin.runtime.region import aws.sdk.kotlin.runtime.config.AwsSdkSetting +import aws.smithy.kotlin.runtime.client.region.RegionProvider import aws.smithy.kotlin.runtime.util.PlatformProvider import aws.smithy.kotlin.runtime.util.PropertyProvider diff --git a/aws-runtime/aws-config/jvm/test/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactoryTest.kt b/aws-runtime/aws-config/jvm/test/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactoryTest.kt index b5df492e23f..5cd6e362b0c 100644 --- a/aws-runtime/aws-config/jvm/test/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactoryTest.kt +++ b/aws-runtime/aws-config/jvm/test/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactoryTest.kt @@ -5,11 +5,11 @@ package aws.sdk.kotlin.runtime.config -import aws.sdk.kotlin.runtime.client.AwsSdkClientConfig import aws.sdk.kotlin.runtime.config.profile.loadAwsSharedConfig import aws.sdk.kotlin.runtime.config.useragent.resolveUserAgentAppId import aws.sdk.kotlin.runtime.config.utils.mockPlatform import aws.smithy.kotlin.runtime.client.* +import aws.smithy.kotlin.runtime.client.region.RegionProvider import aws.smithy.kotlin.runtime.retries.StandardRetryStrategy import aws.smithy.kotlin.runtime.util.PlatformProvider import aws.smithy.kotlin.runtime.util.asyncLazy @@ -129,6 +129,7 @@ private interface TestClient : SdkClient { override val clientName: String = builder.clientName override val logMode: LogMode = builder.logMode ?: LogMode.Default override val region: String? = builder.region + override var regionProvider: RegionProvider? = builder.regionProvider override var useFips: Boolean = builder.useFips ?: false override var useDualStack: Boolean = builder.useDualStack ?: false override val applicationId: String? = builder.applicationId @@ -141,6 +142,7 @@ private interface TestClient : SdkClient { override var clientName: String = "Test" override var logMode: LogMode? = LogMode.Default override var region: String? = null + override var regionProvider: RegionProvider? = null override var useFips: Boolean? = null override var useDualStack: Boolean? = null override var applicationId: String? = null diff --git a/aws-runtime/aws-config/native/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainNative.kt b/aws-runtime/aws-config/native/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainNative.kt index 18ffb383e84..cd29e860991 100644 --- a/aws-runtime/aws-config/native/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainNative.kt +++ b/aws-runtime/aws-config/native/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainNative.kt @@ -7,6 +7,7 @@ package aws.sdk.kotlin.runtime.region import aws.sdk.kotlin.runtime.config.imds.InstanceMetadataProvider import aws.sdk.kotlin.runtime.config.profile.AwsProfile +import aws.smithy.kotlin.runtime.client.region.RegionProvider import aws.smithy.kotlin.runtime.io.Closeable import aws.smithy.kotlin.runtime.util.LazyAsyncValue import aws.smithy.kotlin.runtime.util.PlatformProvider diff --git a/aws-runtime/aws-core/api/aws-core.api b/aws-runtime/aws-core/api/aws-core.api index 612389b04ac..406106edd66 100644 --- a/aws-runtime/aws-core/api/aws-core.api +++ b/aws-runtime/aws-core/api/aws-core.api @@ -35,21 +35,3 @@ public final class aws/sdk/kotlin/runtime/client/AwsClientOption { public final fun getRegion ()Laws/smithy/kotlin/runtime/collections/AttributeKey; } -public abstract interface class aws/sdk/kotlin/runtime/client/AwsSdkClientConfig : aws/smithy/kotlin/runtime/client/SdkClientConfig { - public abstract fun getApplicationId ()Ljava/lang/String; - public abstract fun getRegion ()Ljava/lang/String; - public abstract fun getUseDualStack ()Z - public abstract fun getUseFips ()Z -} - -public abstract interface class aws/sdk/kotlin/runtime/client/AwsSdkClientConfig$Builder { - public abstract fun getApplicationId ()Ljava/lang/String; - public abstract fun getRegion ()Ljava/lang/String; - public abstract fun getUseDualStack ()Ljava/lang/Boolean; - public abstract fun getUseFips ()Ljava/lang/Boolean; - public abstract fun setApplicationId (Ljava/lang/String;)V - public abstract fun setRegion (Ljava/lang/String;)V - public abstract fun setUseDualStack (Ljava/lang/Boolean;)V - public abstract fun setUseFips (Ljava/lang/Boolean;)V -} - diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt index b4debfc4bd8..5b52661c0cf 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt @@ -16,10 +16,6 @@ object AwsRuntimeTypes { val AwsErrorMetadata = symbol("AwsErrorMetadata") val AwsServiceException = symbol("AwsServiceException") val ClientException = symbol("ClientException") - - object Client : RuntimeTypePackage(AwsKotlinDependency.AWS_CORE, "client") { - val AwsSdkClientConfig = symbol("AwsSdkClientConfig") - } } object Endpoint : RuntimeTypePackage(AwsKotlinDependency.AWS_ENDPOINT) { @@ -36,6 +32,8 @@ object AwsRuntimeTypes { object Config : RuntimeTypePackage(AwsKotlinDependency.AWS_CONFIG) { val AbstractAwsSdkClientFactory = symbol("AbstractAwsSdkClientFactory", "config") + val AwsSdkClientConfig = symbol("AwsSdkClientConfig", "config") + object Endpoints : RuntimeTypePackage(AwsKotlinDependency.AWS_CONFIG, "config.endpoints") { val AccountIdEndpointMode = symbol("AccountIdEndpointMode") val resolveEndpointUrl = symbol("resolveEndpointUrl") @@ -54,6 +52,10 @@ object AwsRuntimeTypes { val StaticCredentialsProvider = symbol("StaticCredentialsProvider") val manage = symbol("manage", "auth.credentials.internal", isExtension = true) } + + object Region : RuntimeTypePackage(AwsKotlinDependency.AWS_CONFIG, "region") { + val resolveRegion = symbol("resolveRegion") + } } object Http : RuntimeTypePackage(AwsKotlinDependency.AWS_HTTP) { diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt index 044fd39bb71..dbf63e2cb86 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt @@ -24,20 +24,50 @@ class AwsServiceConfigIntegration : KotlinIntegration { val RegionProp: ConfigProperty = ConfigProperty { name = "region" symbol = KotlinTypes.String.toBuilder().nullable().build() - baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig + baseClass = AwsRuntimeTypes.Config.AwsSdkClientConfig useNestedBuilderBaseClass() documentation = """ The AWS region (e.g. `us-west-2`) to make requests to. See about AWS [global infrastructure](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/) for more information """.trimIndent() + + propertyType = ConfigPropertyType.Custom( + render = { prop, writer -> + writer.write( + "override val #1L: #2T? = builder.#1L ?: #3T { builder.regionProvider?.getRegion() ?: #4T() }", + prop.propertyName, + prop.symbol, + RuntimeTypes.KotlinxCoroutines.runBlocking, + AwsRuntimeTypes.Config.Region.resolveRegion, + ) + }, + ) + + order = -100 + } + + val RegionProviderProp: ConfigProperty = ConfigProperty { + name = "regionProvider" + symbol = RuntimeTypes.SmithyClient.Region.RegionProvider.asNullable() + baseClass = AwsRuntimeTypes.Config.AwsSdkClientConfig + useNestedBuilderBaseClass() + documentation = """ + An optional region provider that determines the AWS region for client operations. When specified, this provider + takes precedence over the default region provider chain, unless a static region is explicitly configured. + The region resolution order is: + 1. Static region (if specified) + 2. Custom region provider (if configured) + 3. Default region provider chain + """.trimIndent() + order = -100 } val UserAgentAppId: ConfigProperty = ConfigProperty { name = "applicationId" symbol = KotlinTypes.String.asNullable() - baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig + baseClass = AwsRuntimeTypes.Config.AwsSdkClientConfig useNestedBuilderBaseClass() documentation = """ An optional application specific identifier. @@ -132,6 +162,7 @@ class AwsServiceConfigIntegration : KotlinIntegration { override fun additionalServiceConfigProps(ctx: CodegenContext): List = buildList { add(RegionProp) + add(RegionProviderProp) if (AwsSignatureVersion4.isSupportedAuthentication(ctx.model, ctx.settings.getService(ctx.model))) { add(CredentialsProviderProp) } diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/BindAwsEndpointBuiltins.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/BindAwsEndpointBuiltins.kt index 5c418be243e..8186804c565 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/BindAwsEndpointBuiltins.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/BindAwsEndpointBuiltins.kt @@ -38,7 +38,7 @@ class BindAwsEndpointBuiltins : KotlinIntegration { Flag to toggle whether to use [FIPS](https://aws.amazon.com/compliance/fips/) endpoints when making requests. ` Disabled by default. """.trimIndent() - baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig + baseClass = AwsRuntimeTypes.Config.AwsSdkClientConfig useNestedBuilderBaseClass() } @@ -50,7 +50,7 @@ class BindAwsEndpointBuiltins : KotlinIntegration { See [https://docs.aws.amazon.com/sdkref/latest/guide/feature-endpoints.html] for more information. ` Disabled by default. """.trimIndent() - baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig + baseClass = AwsRuntimeTypes.Config.AwsSdkClientConfig useNestedBuilderBaseClass() } } diff --git a/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt index 9303d312e12..0a7df490cd9 100644 --- a/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt +++ b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt @@ -45,7 +45,8 @@ class AwsServiceConfigIntegrationTest { val contents = writer.toString() val expectedProps = """ - override val region: String? = builder.region + override val region: String? = builder.region ?: runBlocking { builder.regionProvider?.getRegion() ?: resolveRegion() } + override val regionProvider: RegionProvider? = builder.regionProvider override val credentialsProvider: CredentialsProvider = builder.credentialsProvider ?: DefaultChainCredentialsProvider(httpClient = httpClient, region = region).manage() """ contents.shouldContainOnlyOnceWithDiff(expectedProps) @@ -58,6 +59,16 @@ class AwsServiceConfigIntegrationTest { */ override var region: String? = null + /** + * An optional region provider that determines the AWS region for client operations. When specified, this provider + * takes precedence over the default region provider chain, unless a static region is explicitly configured. + * The region resolution order is: + * 1. Static region (if specified) + * 2. Custom region provider (if configured) + * 3. Default region provider chain + */ + override var regionProvider: RegionProvider? = null + /** * The AWS credentials provider to use for authenticating requests. If not provided a * [aws.sdk.kotlin.runtime.auth.credentials.DefaultChainCredentialsProvider] instance will be used. diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b0713cf239f..81a24b2efbc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,7 @@ coroutines-version = "1.9.0" atomicfu-version = "0.25.0" # smithy-kotlin codegen and runtime are versioned separately -smithy-kotlin-runtime-version = "1.3.30" +smithy-kotlin-runtime-version = "1.3.33" smithy-kotlin-codegen-version = "0.33.30" # codegen