【问题标题】:How to Set required attributes in aws cognito user pool using aws cloudformation template?如何使用 aws cloudformation 模板在 aws cognito 用户池中设置所需属性?
【发布时间】:2018-02-28 08:38:17
【问题描述】:

Aws cognito console screen

在使用 cloudformation 模板创建用户池时,我想添加以下属性(在附加的图像链接中标记)。我在 AWS 文档中没有发现任何有用的信息。

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

有没有人尝试过或对此有任何想法?

【问题讨论】:

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


    【解决方案1】:

    我设法使用 AWS::cognito::UserPool 的 schema 属性来完成它:

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

    【讨论】:

    • 谢谢!!亚马逊需要感到羞耻的是,他们没有指定必需的属性应该具有不同的结构。我花了很多时间才找到你的例子。
    【解决方案2】:

    这是 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
    

    【讨论】:

      【解决方案3】:

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

      实现这一点的最小参数是:

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

      【讨论】:

      • 在验证期间,密钥应为“custom:
      猜你喜欢
      • 2021-05-31
      • 2022-01-21
      • 2017-11-14
      • 2018-02-11
      • 2018-08-29
      • 2020-03-29
      • 2017-04-12
      • 2017-08-12
      • 2019-01-06
      相关资源
      最近更新 更多