gpt4 book ai didi

java - AWSCognitoIdentityProvider.adminCreateUser(...) 无法满足约束 : Member must not be null

转载 作者:行者123 更新时间:2023-12-02 09:46:36 29 4
gpt4 key购买 nike

我正在将 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;

}

}

我在控制台 View 中得到这个:

[ ... {Name: name,AttributeDataType: String,DeveloperOnlyAttribute: false,Mutable: true,Required: false,StringAttributeConstraints: {MinLength: 0,MaxLength: 2048}} ... ]

Exception in thread "main" com.amazonaws.services.cognitoidp.model.InvalidParameterException: 1 validation error detected: Value null at 'userAttributes.1.member.name' failed to satisfy constraint: Member must not be null ...

正如您从 getSchemaAttributes() 的打印中看到的,“name”不是必需的。为什么我收到错误消息说它不能为空?

最佳答案

您是否尝试更改此代码:

                .withUserAttributes(
new AttributeType()
.withValue("dbrower256@yahoo.com"),

类似于:

                .withUserAttributes(
new AttributeType()
.withName(...)
.withValue("dbrower256@yahoo.com"),

关于java - AWSCognitoIdentityProvider.adminCreateUser(...) 无法满足约束 : Member must not be null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56607749/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com