24
我是新的Cognito。我正在嘗試使用Lambda實現AWS Cognito。這是我正在關注的tutorial。AWS Cognito錯誤:'identityPoolId'未能滿足約束條件
AmazonCognitoIdentityClient client =
new AmazonCognitoIdentityClient();
GetOpenIdTokenForDeveloperIdentityRequest tokenRequest = new GetOpenIdTokenForDeveloperIdentityRequest();
tokenRequest.setIdentityPoolId("us-east-1_XXXXXXX");
這是我使用的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;
}
這是輸出
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;
救了我又一個2小時!!! –
@ Chetan-我認爲你應該在這個答案上使用upvotes作爲反饋,使得教程更好,並且比身份池的「Manage Federated Identities」更好的名字 – suku
@Chetan你將如何從用戶池ID獲取身份池ID?或者獲取與cognito用戶關聯的當前角色? –