aws-sdk-java icon indicating copy to clipboard operation
aws-sdk-java copied to clipboard

Getting "Credential should be scoped to a valid region." error when try to create an IAM client by using us-west-2 as a region

Open arjunrajpal opened this issue 10 months ago • 0 comments

Upcoming End-of-Support

  • [X] I acknowledge the upcoming end-of-support for AWS SDK for Java v1 was announced, and migration to AWS SDK for Java v2 is recommended.

Describe the bug

I am trying to create an IAM client using com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder" of "aws-java-sdk-iam-1.12.648.jar

Here is how I try to create an IAM client:

AmazonIdentityManagementClientBuilder
.standard()
.withCredentials(awsCredentialsProvider)
.withEndpointConfiguration("iam.amazonaws.com", region))
build;

When I try to pass region variable as "us-west-2", I get the following error com.amazonaws.services.identitymanagement.model.AmazonIdentityManagementException: Credential should be scoped to a valid region. (Service: AmazonIdentityManagement; Status Code: 403; Error Code: SignatureDoesNotMatch; Request ID: b249c06f-28b4-483b-b967-18eabd3e4ea9; Proxy: null)

When I try to pass "us-east-1" as the region it works correctly without any issues. Also if I try create an IAM client using AmazonIdentityManagementClient(AWSCredentialsProvider awsCredentialsProvider) constructor it works correctly. I feel there is an issue with the client builder of AmazonldentityManagement.

I am creating other aws clients like sqs, sns, dynamodb in a similar way using client builders and I am not getting any such issues.

Can you please help at the earliest? We are blocked on this as we use aws sdks to create resources.

Expected Behavior

It should have created the iam client successfully.

Current Behavior

Fails to create iam client with the following error: com.amazonaws.services.identitymanagement.model.AmazonIdentityManagementException: Credential should be scoped to a valid region. (Service: AmazonIdentityManagement; Status Code: 403; Error Code: SignatureDoesNotMatch; Request ID: b249c06f-28b4-483b-b967-18eabd3e4ea9; Proxy: null)

Reproduction Steps

AmazonIdentityManagementClientBuilder
.standard()
.withCredentials(awsCredentialsProvider)
.withEndpointConfiguration("iam.amazonaws.com", region))
build;

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

1.12.648

JDK version used

openjdk 17.0.8.1 2023-08-22 LTS

Operating System and version

Bitbucket Pipelines

arjunrajpal avatar May 01 '24 14:05 arjunrajpal