-
Notifications
You must be signed in to change notification settings - Fork 977
Description
Describe the bug
When using Region.of(...) to configure a CognitoIdentityProviderAsyncClient, if the region name is provided in uppercase (e.g., EU-WEST-1), the generated service URL contains the region in uppercase, causing authentication requests to fail: https://cognito-idp.EU-WEST-1.amazonaws.com.
leads to an error when making admin API calls.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
The SDK should normalize the region name to lowercase when generating service URLs, ensuring compatibility with AWS services. The expected URL should be: https://cognito-idp.eu-west-1.amazonaws.com
Current Behavior
When passing an uppercase region name to Region.of(...), the generated URL includes the region in uppercase, leading to a 400 Bad Request error from Cognito Identity Provider.
Exception thrown:
software.amazon.awssdk.services.cognitoidentityprovider.model.CognitoIdentityProviderException: Credential should be scoped to a valid region. (Service: CognitoIdentityProvider, Status Code: 400, Request ID: 1*******-****-****-*-***********0)
Reproduction Steps
- Create a
CognitoIdentityProviderAsyncClientbean withRegion.of("EU-WEST-1"):
@Bean
public CognitoIdentityProviderAsyncClient cognitoIdentityProviderAsyncClient() {
return CognitoIdentityProviderAsyncClient
.builder()
.region(Region.of("EU-WEST-1"))
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.build();
}- Call an admin API, such as
adminGetUser:
Mono.fromFuture(
cognitoIdentityProviderAsyncClient
.adminGetUser(
AdminGetUserRequest
.builder()
.username(username)
.userPoolId(poolId)
.build()))
.map(response -> ...);- Observe the exception indicating an invalid region: Credential should be scoped to a valid region
Possible Solution
The Region.of(...) method should automatically convert region names to lowercase before generating service URLs.
This behavior should align with AWS's expected endpoint formats and ensure that uppercase inputs do not break API calls.
Additional Information/Context
No response
AWS Java SDK version used
software.amazon.awssdk:cognitoidentityprovider:2.30.7
JDK version used
21
Operating System and version
Windows 11 Pro, SAM-CLI 1.132.0 and Docker v4.37.1