AWS Cognito错误:'identityPoolId'无法满足约束

suk*_*uku 36 amazon-web-services amazon-cognito

我是新的Cognito.我正在尝试使用Lambda实现AWS Cognito.这是我关注的教程.

AmazonCognitoIdentityClient client =
                new AmazonCognitoIdentityClient();
    GetOpenIdTokenForDeveloperIdentityRequest tokenRequest = new GetOpenIdTokenForDeveloperIdentityRequest();
    tokenRequest.setIdentityPoolId("us-east-1_XXXXXXX");
Run Code Online (Sandbox Code Playgroud)

这是我在setIdentityPoolId中使用的池ID

在此输入图像描述

这是JUnit测试

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; 
}
Run Code Online (Sandbox Code Playgroud)

这是输出

user found
user password matched
Run Code Online (Sandbox Code Playgroud)

但是我收到了以下错误,因此return user声明失败了

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; 
Run Code Online (Sandbox Code Playgroud)

Che*_*hta 115

您使用Cognito用户池标识作为标识池标识.他们是两个不同的东西.标识池ID的格式为us-east-1:XXXX-XXXXXX-XXXX-XXXX.

要获取标识池ID,您应使用Cognito控制台的"管理联合身份"部分而不是"管理用户池"部分.希望这可以帮助.

  • @ Chetan-我认为你应该使用这个答案的upvotes作为反馈,使教程更好,更好的名称比身份池的"管理联合身份"更好 (3认同)