7
votes

I'm using this CloudFormation template to create a Cognito User Pool:

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Template creates AWS Cognito UserPool.",
    "Resources": {
        "CognitoUserPool": {
            "Type": "AWS::Cognito::UserPool",
            "Properties": {
                "Policies": {
                    "PasswordPolicy": {
                        "MinimumLength": 8,
                        "RequireUppercase": true,
                        "RequireLowercase": true,
                        "RequireNumbers": true,
                        "RequireSymbols": true
                    }
                },
                "Schema": [
                    {
                        "Name": "sub",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": false,
                        "Required": true,
                        "StringAttributeConstraints": {
                            "MinLength": "1",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "name",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "given_name",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "family_name",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "middle_name",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "nickname",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "preferred_username",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "profile",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "picture",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "website",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "email",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": true,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "email_verified",
                        "AttributeDataType": "Boolean",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false
                    },
                    {
                        "Name": "gender",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "birthdate",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "10",
                            "MaxLength": "10"
                        }
                    },
                    {
                        "Name": "zoneinfo",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "locale",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "phone_number",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "phone_number_verified",
                        "AttributeDataType": "Boolean",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false
                    },
                    {
                        "Name": "address",
                        "AttributeDataType": "String",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "StringAttributeConstraints": {
                            "MinLength": "0",
                            "MaxLength": "2048"
                        }
                    },
                    {
                        "Name": "updated_at",
                        "AttributeDataType": "Number",
                        "DeveloperOnlyAttribute": false,
                        "Mutable": true,
                        "Required": false,
                        "NumberAttributeConstraints": {
                            "MinValue": "0"
                        }
                    }
                ],
                "LambdaConfig": {},
                "AutoVerifiedAttributes": [
                    "email"
                ],
                "UsernameAttributes": [
                    "email"
                ],
                "SmsVerificationMessage": "Your verification code is {####}. ",
                "EmailVerificationMessage": "Your app verification code is {####}. ",
                "EmailVerificationSubject": "Your app verification code",
                "SmsAuthenticationMessage": "Your authentication code is {####}. ",
                "MfaConfiguration": "OFF",
                "EmailConfiguration": {},
                "UserPoolTags": {},
                "AdminCreateUserConfig": {
                    "AllowAdminCreateUserOnly": false,
                    "UnusedAccountValidityDays": 7,
                    "InviteMessageTemplate": {
                        "SMSMessage": "Your username is {username} and temporary password is {####}. ",
                        "EmailMessage": "Your username is {username} and temporary password is {####}. ",
                        "EmailSubject": "Your temporary password"
                    }
                }         
            }
        }          
    },
    "Outputs": {
        "CognitoUserPoolARN": {
            "Value": {
                "Fn::GetAtt": [
                    "CognitoUserPool",
                    "Arn"
                ]
            },
            "Export": {
                "Name": {
                    "Fn::Sub": "${AWS::StackName}-cognito-userpool-arn"
                }
            }
        }
    }
}

The "Schema" is the output of a current and working User Pool:

aws cognito-idp describe-user-pool --user-pool-id POOL_ID

I have this error when creating the stack (with a different name of course), even though the stack is valid:

1 validation error detected: Value 'phone_number_verified' at 'schema.18.member.name' failed to satisfy constraint: Member must have length less than or equal to 20 (Service: AWSCognitoIdentityProviderService; Status Code: 400; Error Code: InvalidParameterException; Request ID: ID)

The phone_number_verified is Boolean.

3

3 Answers

5
votes

The issue was: The Name: "phone_number_verified" is too long (over 20 chars). Changing it to something like "phonenumber_verified" will work.

enter image description here

Note: the command aws cloudformation validate-template won't catch this.

1
votes

The hint is in the error message but I agree it is terribly misleading. It does not mention which Member it is referring to. For this api, it's the Schema property that you have above.

You will notice that you have 21 attributes under Schema. Since the API accepts at most 20 at a time, you could remove any one of the attributes and try again. I think that once you create with the 20 resources, you should be able to add it back.

1
votes

The error i got is this,

1 validation error detected: Value 'custom:cognitoIdentityId' at 
'schema.3.member.name' failed to satisfy constraint: .
Member must have length less than or equal to 20 
(Service: AWSCognitoIdentityProviderService; Status Code: 400; 
Error Code: InvalidParameterException; 
Request ID: 2c7c69a9-68ca-4ccc-a951-ab3fa0be2689)

According to this, the "name" attribute is too long. The value of the name attribute is "custom:cognitoIdentityId".

According to the documentation, Minimum: 1 and Maximum: 20.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-userpool-schemaattribute.html#cfn-cognito-userpool-schemaattribute-name