首页 > 解决方案 > AWS Cognito:无法使用 aws cli 为 create-user-pool 设置一些属性

问题描述

我正在尝试使用来自 json 文件的 AWS CLI 在 cognito 上创建一个用户池。正在创建池,但我无法设置它的某些属性。

注意:下面附加的一些快照取自用于创建用户池的 AWS Docs

  1. 我无法找到将电子邮件设置为验证属性的方法。

    快照:

    在此处输入图像描述

  2. 尽管我在 json 文件中指定了电子邮件消息和主题,但并未自定义它们。这让我想到了另一个问题(第 3 点)。

    在此处输入图像描述

  3. 通过 CLI 创建用户池的 AWS 文档提到了三个属性。

快照:

在此处输入图像描述

下面是我为创建池而形成的 JSON 对象

{
    "PoolName": "xxx-userpool-local",
    "Policies": {
        "PasswordPolicy": {
            "MinimumLength": 8,
            "RequireUppercase": true,
            "RequireLowercase": true,
            "RequireNumbers": true,
            "RequireSymbols": true,
            "TemporaryPasswordValidityDays": 7
        }
    },
    "UsernameAttributes": [
        "email"
    ],
    "EmailVerificationMessage": "Please click the link below to verify your account. {####}",
    "EmailVerificationSubject": "Your account is ready",
    "VerificationMessageTemplate": {
        "EmailMessage": "Please click the link below to verify your account. {####}",
        "EmailSubject": "Your account is ready",
        "EmailMessageByLink": "Please click the link below to verify your account. {####}",
        "EmailSubjectByLink": "Your account is ready",
        "DefaultEmailOption": "CONFIRM_WITH_LINK"
    },
    "AdminCreateUserConfig": {
        "AllowAdminCreateUserOnly": false
    },
    "UsernameConfiguration": {
        "CaseSensitive": true
    },
    "AccountRecoverySetting": {
        "RecoveryMechanisms": [
            {
                "Priority": 1,
                "Name": "verified_email"
            }
        ]
    }
}

标签: amazon-web-servicesamazon-cognitoaws-cli

解决方案


  1. 控制台中的此选项映射到AutoVerifiedAttributesCLI 中。要将电子邮件设置为验证属性,请将以下代码片段添加到您的 JSON 输入中:
"AutoVerifiedAttributes": [
 "email"
]
  1. 它映射到AdminCreateUserConfig.InviteMessageTemplateCLI 中。
"AdminCreateUserConfig": {
  "AllowAdminCreateUserOnly": false,
  "InviteMessageTemplate": {
    "EmailMessage": "Your username is {username} and temporary password is {####}. ",
    "EmailSubject": "Your temporary password"
  }
}
  1. 您可以使用以下配置来选择验证链接作为选项而不是验证码。
"VerificationMessageTemplate": {
  "EmailMessageByLink": "Please click the link below to verify your email address. {##Verify Email##} ",
  "EmailSubjectByLink": "Your verification link",
  "DefaultEmailOption": "CONFIRM_WITH_LINK"
}

推荐阅读