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

时间:2016-05-14 07:02:13

标签: amazon-web-services amazon-cognito

我是新的Cognito。我正在尝试使用Lambda实现AWS Cognito。这是我关注的tutorial

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

这是我在setIdentityPoolId

中使用的池ID

enter image description here

这是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; 
}

这是输出

user found
user password matched

但是我收到以下错误,因此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; 

3 个答案:

答案 0 :(得分:110)

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

要获取身份池ID,您应该使用&#34;管理联合身份&#34; Cognito控制台的一部分不是&#34;管理用户池&#34;部分。希望这会有所帮助。

答案 1 :(得分:1)

您可以在User Pools > Federated Identities > App clients > App client id

中找到它

enter image description here

答案 2 :(得分:0)

仅需注意:您还可以在项目的aws-exports.js中找到正确的用户池应用程序客户端ID。该属性名称为“ aws_user_pools_web_client_id”