【发布时间】:2019-10-31 06:13:38
【问题描述】:
我正在尝试创建一个堆栈,该堆栈将创建一个用户池及其应用程序客户端和身份池。这是堆栈:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters" : {
"CognitoUserPoolName": {
"Description": "Name of the Cognito user pool as a parameter passed into this template.",
"Type": "String"
}
},
"Resources": {
"UserPool": {
"Type": "AWS::Cognito::UserPool",
"Properties": {
"UserPoolName" : {
"Ref": "CognitoUserPoolName"
},
"Policies": {
"PasswordPolicy": {
"MinimumLength": 8,
"RequireUppercase": true,
"RequireLowercase": true,
"RequireNumbers": true,
"RequireSymbols": true
}
},
"Schema": [
{
"Name": "name",
"AttributeDataType": "String",
"Mutable": true,
"Required": false
},
{
"Name": "email",
"AttributeDataType": "String",
"Mutable": false,
"Required": true
},
{
"Name": "phone_number",
"AttributeDataType": "String",
"Mutable": false,
"Required": false
}
],
"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"
}
}
}
},
"UserPoolClient": {
"Type": "AWS::Cognito::UserPoolClient",
"Description": "App Client.",
"DependsOn": "UserPool",
"Properties": {
"ClientName": {
"Fn::Sub": "${CognitoUserPoolName}Client"
},
"ExplicitAuthFlows": [
"ADMIN_NO_SRP_AUTH"
],
"GenerateSecret": false,
"RefreshTokenValidity": 30,
"UserPoolId": {
"Ref": "UserPool"
}
}
},
"IdentityPool": {
"Type" : "AWS::Cognito::IdentityPool",
"DependsOn": ["UserPool", "UserPoolClient"],
"Properties" : {
"AllowUnauthenticatedIdentities" : false,
"CognitoIdentityProviders" : [
{
"ClientId": {
"Ref": "UserPool"
},
"ProviderName": {
"Fn::GetAtt": [
"UserPool",
"Arn"
]
}
}
],
"IdentityPoolName" : {
"Fn::Sub": "${CognitoUserPoolName}IdentityPool"
}
}
}
},
"Outputs": {
"UserPoolARN": {
"Value": {
"Fn::GetAtt": [
"UserPool",
"Arn"
]
}
}
}
}
我不断收到此错误:
dentityPool CREATE_FAILED 1 validation error detected: Value 'us-east-1_<>' at 'cognitoIdentityProviders.1.member.clientId' failed to satisfy constraint: Member must satisfy regular expression pattern: [\w_]+ (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: ValidationException; Request ID: <>)
User Pool ID 的格式似乎不正确。
我尝试像这样编辑CognitoIdentityProviders:
"CognitoIdentityProviders" : [
{
"ClientId": {
"Ref": "UserPool"
}
},
{
"ClientId": {
"Ref": "UserPoolClient"
}
}
],
但我不断收到同样的错误。我之前使用控制台创建了一个身份池,你应该同时添加User Pool ID和App Client ID,而User Pool ID的格式为us-east-1-1_string。
6 月 18 日更新
按照下面 jens 的回答,我能够创建身份池。但是,User Pool ID 和 App client id 都具有 User Pool ID 的值:us-east-1-1_string。
我尝试添加另一个这样的提供商:
"ClientId": {
"Ref": "UserPoolClient"
},
"ProviderName": {
"Fn::GetAtt": [
"UserPool",
"ProviderName"
]
}
它确实创建了正确的提供者:
-
User Pool ID:us-east-1-1_string。例如:us-east-1_Ab129faBb -
App client id:string。例如:7lhlkkfbfb4q5kpp90urffao但是提供者有重复。 我试过了
-
将
App client id,Provider 名称改为UserPoolClient,但创建失败。 -
删除
App client id的ProviderName但创建失败。
【问题讨论】:
标签: amazon-web-services amazon-cloudformation amazon-cognito