Skip to content

Static profile credentials cannot be resolved if a region cannot be detected #581

@ianbotsf

Description

@ianbotsf

Describe the bug

When resolving profile credentials (e.g., in a ~/.aws/credentials file), the credentials provider throws an exception if the default region resolver chain does successfully detect a region (e.g., in the profile, via env vars, etc.). This happens even if the profile credentials are purely static and don't require a region. Further note that an explicit region passed to a client constructor are unused in region resolution for the purposes of parsing profile credentials.

Expected behavior

Users with static profile credentials should be able to use those credentials successfully without the region resolver needing to detect the region.

Current behavior

Users with static profile credentials get an exception when the region resolver cannot detect the region.

Steps to Reproduce

Create an AWS profile that explicitly specifies aws_access_key_id and aws_secret_access_key but not region. Also ensure that no region is available via AWS_REGION env var, aws.region system property, or via IMDS (e.g., on EC2). Then attempt to create and use an AWS client (e.g., S3):

S3Client
    .fromEnvironment {
        region = "us-west-2"
    }
    .listBuckets { } // throws exception because no credentials can be resolved

Workarounds that do succeed include adding region to the AWS profile or explicitly providing a region to an explicitly-chosen profile credentials provider:

S3Client
    .fromEnvironment {
        region = "us-west-2"
        credentialsProvider = ProfileCredentialsProvider(region = "us-west-2")
    }
    .listBuckets { }

Possible Solution

Remove the requirement that a region resolves correctly for static credentials which do not require a region.

Context

No response

AWS Kotlin SDK version used

0.14.2-beta

Platform (JVM/JS/Native)

JVM

Operating System and version

AL2

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions