AWSCognitoIdentityProvider.adminCreateUser (...) не удалось удовлетворить ограничение: элемент не должен быть нулевым - PullRequest
0 голосов
/ 15 июня 2019

Я использую Eclipse для 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;

    }

}

Я получаю это в Console View:

[... {Name: name, AttributeDataType: String, DeveloperOnlyAttribute: false, Mutable: true, Обязательный: false, StringAttributeConstraints: {MinLength: 0, MaxLength: 2048}} ...]

Исключение в потоке "main" com.amazonaws.services.cognitoidp.model.InvalidParameterException: 1 обнаружена ошибка проверки: значение null в 'userAttributes.1.member.name' не удовлетворяет ограничению: элемент не должен быть нулевым .. .

Как видно из распечатки getSchemaAttributes (), "name" не требуется. Почему я получаю сообщение о том, что оно не может быть нулевым?

1 Ответ

1 голос
/ 15 июня 2019

Вы пытались изменить этот код:

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

На что-то вроде:

                .withUserAttributes(
                        new AttributeType()
                        .withName(...)
                        .withValue("dbrower256@yahoo.com"),
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...