2016-05-14 17 views
24

私は新しいCognitoです。私はラムダを使ってAWS Cognitoを実装しようとしています。これは私が従うtutorialです。AWS Cognitoエラー: 'identityPoolId'が制約を満たすのに失敗しました

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

これはsetIdentityPoolId

に私が使用していますプールIDで

enter image description here

これはこれは、出力

user found 
user password matched 
ある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; 
} 

です

しかし、私は次のエラーを取得しています、したがって、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; 

答えて

82

を失敗しているあなたはアイデンティティ・プールIDとしてCognitoユーザー・プールIDを使用しています。彼らは2つの異なるものです。アイデンティティプールIDの形式は、us-east-1:XXXX-XXXXXX-XXXX-XXXXです。

IDプールIDを取得するには、Cognitoコンソールの[Manage User Pools]セクションではなく、[Manage Federated Identities]の部分を使用する必要があります。お役に立てれば。

+1

私は別の2時間を保存しました! –

+3

@ Chetan-私はあなたがIDプールの "連合アイデンティティを管理する"よりも良いチュートリアルを作るためにフィードバックとしてこの答えのアップボーンを使うべきだと思います。 – suku

+0

@ChetanユーザープールIDからIDプールIDを取得する方法は?または、Cognitoユーザーに関連付けられている現在の役割を取得しますか? –

関連する問題