awslabs / aws-sdk-kotlin

Multiplatform AWS SDK for Kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create a StaticRegionProvider

cloudshiftchris opened this issue · comments

Describe the feature

Create a StaticRegionProvider class to explicitly set a region to use.

Is your Feature Request related to a problem?

Currently Kotlin SDK does not have a mechanism to explicitly set the region via a RegionProvider; this is useful for say development environments (outside of AWS) where the region can't be directly inferred and configuration is integrated with other application configuration (i.e. no using system properties or environment variables)

Proposed Solution

public class StaticRegionProvider(private val region: String) : RegionProvider {
    override suspend fun getRegion(): String = region
}

Describe alternative solutions or features you've considered

See proposed solution.

Acknowledge

  • I may be able to implement this feature request

AWS Kotlin SDK version used

029.0-beta

Platform (JVM/JS/Native)

JVM

Operating System and version

MacOS

Is this just a "nice to have" request or is this blocking something for you?

As far as I understand the request you can get this now by wrapping client creation in a way that you consult your own region provider and pass that to client construction.

e.g.

val resolvedRegion = regionProvider.getRegion()
val s3 = S3Client.fromEnvironment{
    region = resolvedRegion
}

Not blocking anything atm, have done as noted above, creating our own StaticRegionProvider driven by configuration.

Q: what are RegionProviders used for in Kotlin SDK? They aren't symmetrical with CredentialsProvider behaviour (provider set at construction time, queried for each API call). Kotlin SDK clients look to use a stringly-typed region parameter at construction time.

Q: what are RegionProviders used for in Kotlin SDK? They aren't symmetrical with CredentialsProvider behaviour (provider set at construction time, queried for each API call). Kotlin SDK clients look to use a stringly-typed region parameter at construction time.

They're used in fromEnvironment when we need to try and auto detect the region that the client should be configured for. Unlike credentials, region is static once set and doesn't change through the lifetime of a client (e.g. region doesn't expire, your EC2 instance isn't going to magically be in a different region, etc). If you need to talk to a different region you would create a new client or use the withConfig extension (see developer guide here).