AWS Region selection - AWS SDK for Kotlin

AWS Region selection

With AWS Regions, you can access AWS services that operate in a specific geographic area. This can be useful both for redundancy and to keep your data and applications running close to where you and your users will access them.

Default Region provider chain

When loading a service client’s configuration from the environment, the following lookup process is used:

  1. Any explicit Region set on the builder.

  2. The aws.region JVM system property is checked. If it’s set, that Region is used in the configuration of the client.

  3. The AWS_REGION environment variable is checked. If it’s set, that Region is used in the configuration of the client.

    1. Note: This environment variable is set by the Lambda container.

  4. The SDK checks the AWS shared configuration file. If the region property is set for the active profile, the SDK uses it.

    1. The AWS_CONFIG_FILE environment variable can be used to customize the location of the shared config file.

    2. The aws.profile JVM system property or the AWS_PROFILE environment variable can be used to customize the profile that the SDK loads.

  5. The SDK attempts to use the Amazon EC2 Instance Metadata Service to determine the Region of the currently running EC2 instance.

  6. If the Region still isn’t resolved at this point, client creation fails with an exception.