如何使用 aws cloudformation 模板在 aws cognito 用户池中设置所需的属性?

How to Set required attributes in aws cognito user pool using aws cloudformation template?

Aws cognito console screen

在使用 cloudformation 模板创建用户池时,我想添加以下属性(在附图中标记 link)。我在 AWS 文档中找不到任何有用的信息。

它允许设置 Alias 属性,如 aws cloudformation cognito documentation 中所述。

有人试过这个或对此有任何想法吗?

我设法使用 AWS::cognito::UserPool 的架构属性完成了它:

"myApiUserPool": {
  "Type": "AWS::Cognito::UserPool",
  "Properties": {
    "AdminCreateUserConfig": {
      "AllowAdminCreateUserOnly": true
    },
    "Schema": [
      {
        "Mutable": false,
        "Name": "email",
        "Required": true
      },
      {
        "Mutable": false,
        "Name": "family_name",
        "Required": true
      },
      {
        "Mutable": false,
        "Name": "name",
        "Required": true
      }
    ],
    "AutoVerifiedAttributes": [
      "email"
    ],
    "UserPoolName": {
      "Fn::Sub": "myApiUserPool${envParameter}"
    }
  }
}

这里是 YAML 的例子。

注意:您不能只更新属性,您需要删除用户池并使用新属性重新创建它(只需注释掉您的池部分并重新部署它)。否则它会要求一个 AttributeDataType,如果你包含它,它会创建一个自定义属性而不是标准属性。

CognitoUserPool:
  Type: AWS::Cognito::UserPool
  Properties:
    # Generate a name based on the stage
    UserPoolName: ${self:custom.stage}-cfp-user-pool
    AliasAttributes:
      - phone_number
      - email
      - preferred_username
    Policies:
      PasswordPolicy:
        MinimumLength: 8
    Schema:
      - Name: email
        Required: true
        Mutable: true

添加@jWang1 并考虑到您不想删除具有大量活跃用户的用户池,但您确实需要在注册过程中添加一个参数,然后您只需将 custom attribute 添加到模板,并通过您的身份验证库或自定义实现

将其强制执行为 必需的

实现此目的的最小参数是:

UserPool:
    Type: AWS::Cognito::UserPool
    Properties:
        Schema:
        -
          Name: <attr name>
          AttributeDataType: Boolean | DateTime | Number | String