【问题标题】:Cloudformation: Error: Member must have length less than or equal to 20Cloudformation:错误:成员的长度必须小于或等于 20
【发布时间】:2019-09-26 10:19:13
【问题描述】:

我正在使用此 CloudFormation 模板来创建 Cognito 用户池:

{
    "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"
                }
            }
        }
    }
}

"Schema"当前有效的用户池的输出:

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

创建堆栈时出现此错误(当然使用不同的名称),即使堆栈是有效的:

检测到 1 个验证错误:“schema.18.member.name”处的值“phone_number_verified”未能满足约束:成员的长度必须小于或等于 20(服务:AWSCognitoIdentityProviderService;状态代码:400;错误代码: InvalidParameterException;请求 ID:ID)

phone_number_verified 是布尔值。

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-cognito


    【解决方案1】:

    问题是:名称:“phone_number_verified”太长(超过 20 个字符)。将其更改为“phonenumber_verified”之类的名称即可。

    注意aws cloudformation validate-template 命令不会捕捉到这一点。

    【讨论】:

      【解决方案2】:

      提示在错误消息中,但我同意它非常具有误导性。 它没有提到它指的是哪个Member。对于这个 api,它是上面的 Schema 属性。

      您会注意到Schema 下有 21 个属性。由于 API一次最多接受 20 个,因此您可以删除任何一个属性并重试。 我认为一旦你用这 20 个资源创建,你应该可以将其添加回来。

      【讨论】:

      • 感谢您的回答。我又检查了一遍,在模板中,Schema 下有 20 个属性。如果我删除phone_number_verified 对象,堆栈会正常创建而不会出错。
      • 抱歉,我不这么认为。如果你编辑它,我会的。
      • 缺少什么?我提到删除了他们中的任何一个都应该这样做,而你删除了phone_number_verified,这样就行了,对吗?
      • 我不认为这个错误是因为属性的数量,而是属性名称的长度。请注意,Cognito 将始终为您的属性名称添加前缀 custom:,并将计算包括前缀在内的长度。
      • 这个答案是错误的。如错误所示 - phone_number_verified 是第 18 个属性。问题在于名称的长度——它有 21 个字符长。 @Viet 下面的答案是正确的。
      【解决方案3】:

      我得到的错误是这样的,

      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)
      

      据此,“名称”属性太长了。 name 属性的值为“custom:cognitoIdentityId”。

      根据文档,最小值:1 和最大值:20。

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

      【讨论】:

        猜你喜欢
        • 2019-08-22
        • 2022-07-07
        • 1970-01-01
        • 1970-01-01
        • 2020-06-07
        • 2020-06-10
        • 1970-01-01
        • 2019-03-03
        • 1970-01-01
        相关资源
        最近更新 更多