我正在将Eclipse for Java与AWS Toolkit结合使用。我运行这段代码:
public class Main {
public static void main(String[] args) {
AmazonCognitoIdentityClient client = new AmazonCognitoIdentityClient();
client.trial();
UserType userType = client.signUp();
}
}
public class AmazonCognitoIdentityClient {
public void trial() {
AWSCognitoIdentityProvider cognitoClient = getAmazonCognitoIdentityClient();
System.out.println(userPoolType.getSchemaAttributes());
}
public AWSCognitoIdentityProvider getAmazonCognitoIdentityClient() {
ClasspathPropertiesFileCredentialsProvider propertiesFileCredentialsProvider =
new ClasspathPropertiesFileCredentialsProvider();
return AWSCognitoIdentityProviderClientBuilder.standard()
.withCredentials(propertiesFileCredentialsProvider)
.withRegion("us-east-1")
.build();
}
public UserType signUp() {
AWSCognitoIdentityProvider cognitoClient = getAmazonCognitoIdentityClient();
AdminCreateUserRequest cognitoRequest = new AdminCreateUserRequest()
.withUserPoolId("us-east-1_PJa8U1lw3")
.withUsername("yahoo")
.withUserAttributes(
new AttributeType()
.withValue("dbrower256@yahoo.com"),
new AttributeType()
.withName("sub")
.withValue("sub"),
new AttributeType()
.withName("name")
.withValue("Daniel"),
new AttributeType()
.withName("given_name")
.withValue("Daniel"),
new AttributeType()
.withName("family_name")
.withValue("Brower"),
new AttributeType()
.withName("phone_number")
.withValue("9032761046"),
new AttributeType()
.withName("email_verified")
.withValue("true"))
.withTemporaryPassword("TEMPORARY_PASSWORD")
.withMessageAction("SUPPRESS")
.withDesiredDeliveryMediums(DeliveryMediumType.EMAIL)
.withForceAliasCreation(Boolean.FALSE);
AdminCreateUserResult createUserResult = cognitoClient.adminCreateUser(cognitoRequest);
UserType cognitoUser = createUserResult.getUser();
return cognitoUser;
}
}
我在控制台视图中得到了这个
[... {名称:名称,AttributeDataType:字符串,DeveloperOnlyAttribute:false,可变:true,必填:false,StringAttributeConstraints:{MinLength:0,MaxLength:2048}} ...]
线程“ main”中的异常com.amazonaws.services.cognitoidp.model.InvalidParameterException:检测到1个验证错误:“ userAttributes.1.member.name”处的值为null未能满足约束条件:Member不能为null ..
从getSchemaAttributes()的打印中可以看到,“ name”不是必需的。为什么我会收到错误消息,说它不能为空?
答案 0 :(得分:1)
您尝试更改此代码:
.withUserAttributes(
new AttributeType()
.withValue("dbrower256@yahoo.com"),
类似:
.withUserAttributes(
new AttributeType()
.withName(...)
.withValue("dbrower256@yahoo.com"),