【发布时间】:2018-02-28 08:38:17
【问题描述】:
在使用 cloudformation 模板创建用户池时,我想添加以下属性(在附加的图像链接中标记)。我在 AWS 文档中没有发现任何有用的信息。
它允许设置别名属性,如 aws cloudformation cognito documentation 中所述。
有没有人尝试过或对此有任何想法?
【问题讨论】:
标签: amazon-web-services amazon-cloudformation aws-cognito
在使用 cloudformation 模板创建用户池时,我想添加以下属性(在附加的图像链接中标记)。我在 AWS 文档中没有发现任何有用的信息。
它允许设置别名属性,如 aws cloudformation cognito documentation 中所述。
有没有人尝试过或对此有任何想法?
【问题讨论】:
标签: amazon-web-services amazon-cloudformation aws-cognito
我设法使用 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}"
}
}
}
【讨论】:
这是 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
【讨论】: