2016-05-14 10 views
24

Jestem nowym Cognito. Próbuję zaimplementować AWS Cognito za pomocą Lambda. To jest tutorial.AWS Cognito Error: "identityPoolId" nie spełniło warunków ograniczenia

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

To Id basen, który używam w setIdentityPoolId

enter image description here

To jest test 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; 
} 

To jest wyjście

user found 
user password matched 

Ale ja otrzymuję następujący błąd i stąd stwierdzenie return user zawodzi

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; 

Odpowiedz

82

Używasz basen użytkownik id Cognito jako identyfikator basenie tożsamość. To są dwie różne rzeczy. Identyfikatory paczek tożsamości mają format US-wschód-1: XXXX-XXXXXX-XXXX-XXXX.

Aby uzyskać identyfikator puli tożsamości, należy użyć sekcji "Zarządzaj tożsamością federacyjną" konsoli Cognito, a nie sekcji "Zarządzaj pulami użytkowników". Mam nadzieję że to pomoże.

+1

zaoszczędziło mi kolejne 2 godziny !!! –

+3

@ Chetan- Myślę, że powinieneś użyć repozytoriów w tej odpowiedzi jako informacji zwrotnej, aby tutorial był lepszy, a nazwa lepsza niż "Zarządzaj tożsamością federacyjną" dla Identity Pool – suku

+0

@Chetan W jaki sposób otrzymasz identyfikator puli tożsamości od identyfikatora puli użytkowników? Lub uzyskać aktualną rolę powiązaną z użytkownikiem cognito? –

Powiązane problemy