AWS Cognito Error: 'identityPoolId' failed to satisfy constraint

Amazon Web-ServicesAmazon Cognito

Amazon Web-Services Problem Overview


I am new Cognito. I am trying to implement AWS Cognito using Lambda. This is the tutorial I am following.

AmazonCognitoIdentityClient client =
				new AmazonCognitoIdentityClient();
	GetOpenIdTokenForDeveloperIdentityRequest tokenRequest = new GetOpenIdTokenForDeveloperIdentityRequest();
	tokenRequest.setIdentityPoolId("us-east-1_XXXXXXX");

This is the pool Id that I am using in the setIdentityPoolId

enter image description here

This is the JUnit test

public class AuthenticateUser implements RequestHandler<Object, Object> {

@Override
public Object handleRequest(Object input, Context context) {
	
	AuthenticateUserResponse authenticateUserResponse = new AuthenticateUserResponse();
	@SuppressWarnings("unchecked")
	LinkedHashMap inputHashMap = (LinkedHashMap)input;
	User user = authenticateUser(inputHashMap);
    return null;
}

public User authenticateUser(LinkedHashMap input){
	User user = null;
	String userName = (String) input.get("userName");
	String passwordHash = (String) input.get("passwordHash");
	
	try {
		AmazonDynamoDBClient client = new AmazonDynamoDBClient();
		client.setRegion(Region.getRegion(Regions.US_EAST_1));
		DynamoDBMapper mapper = new DynamoDBMapper(client);
		user = mapper.load(User.class, userName);
		
		if(user != null){
			System.out.println("user found");
			if(user.getPasswordHash().equals(passwordHash)){
				System.out.println("user password matched");
				String openIdToken = getOpenIdToken(user.getUserId());
				user.setOpenIdToken(openIdToken);
				return user;
			} else {
				System.out.println("password unmatched");
			}
		} else {
			System.out.println("user not found");
		}
	} catch (Exception e) {
		System.out.println("Error: " + e.toString());
	}
	
	return user; 
}

This is the output

user found
user password matched

But I am getting the following error and hence, the return user statement is failing

1 validation error detected: Value 'us-east-1_XXXXXX' at 'identityPoolId' 
failed to satisfy constraint: Member must satisfy regular expression pattern: [\w-]+:[0-9a-f-]+ 
(Service: AmazonCognitoIdentity; Status Code: 400; Error Code: ValidationException; 

Amazon Web-Services Solutions


Solution 1 - Amazon Web-Services

You are using a Cognito user pool id as the identity pool id. They are two different things. Identity pool ids are of format us-east-1:XXXX-XXXXXX-XXXX-XXXX.

To get an identity pool id you should use the "Manage Federated Identities" parts of the Cognito console not the "Manage User Pools" section. Hope this helps.

Solution 2 - Amazon Web-Services

Just a note: you can also find the correct user pool app client id in your project's aws-exports.js. The property name is "aws_user_pools_web_client_id"

Solution 3 - Amazon Web-Services

You can find it in User Pools > Federated Identities > App clients > App client id

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsukuView Question on Stackoverflow
Solution 1 - Amazon Web-ServicesChetan MehtaView Answer on Stackoverflow
Solution 2 - Amazon Web-ServicesBarbara PrusiewiczView Answer on Stackoverflow
Solution 3 - Amazon Web-ServicesAbudayahView Answer on Stackoverflow