[英]Unable to reference CloudFormation resource in serverless.yml. Invalid variable reference syntax for variable UserPoolId
我正在使用无服务器框架将无服务器应用程序部署到 AWS。 但是,CloudFormation 部分没有按预期工作。 我在网上查了一下,没有发现我的 YAML 有什么问题。
我正在创建一个UserPool
,然后使用UserPoolClient
创建UserPool
。 我有以下 YAML resources:
resources:
Resources:
HttpBucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: ${self:service}-${UserPoolId}
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
UserPool:
Type: "AWS::Cognito::UserPool"
Properties:
UserPoolName: ${self:service}-user-pool
MfaConfiguration: "OFF"
EmailVerificationSubject: "Your verification code"
EmailVerificationMessage: "Your verification code is {####}. "
Schema:
- Name: name
AttributeDataType: String
Mutable: true
Required: true
- Name: email
AttributeDataType: String
Mutable: false
Required: true
- Name: teamName
AttributeDataType: String
Mutable: true
Required: false
- Name: custom:supportedTeam
AttributeDataType: String
Mutable: true
Required: false
- Name: custom:payment
AttributeDataType: String
Mutable: true
Required: false
DeveloperOnlyAttribute: true
UsernameAttributes:
- email
AutoVerifiedAttributes:
- email
AdminCreateUserConfig:
InviteMessageTemplate:
EmailMessage: 'Your username is {username} and temporary password is {####}. '
EmailSubject: Your temporary password
SMSMessage: 'Your username is {username} and temporary password is {####}. '
UnusedAccountValidityDays: 7
AllowAdminCreateUserOnly: false
Policies:
PasswordPolicy:
RequireLowercase: true
RequireSymbols: false
RequireNumbers: true
MinimumLength: 6
RequireUppercase: true
UserPoolClient:
Type: "AWS::Cognito::UserPoolClient"
Properties:
ClientName: ${self:service}-client
GenerateSecret: false
UserPoolId:
Ref: UserPool
Outputs:
UserPoolId:
Value:
Ref: UserPool
Export:
Name: "UserPool::Id"
UserPoolClientId:
Value:
Ref: UserPoolClient
Export:
Name: "UserPoolClient::Id"
指定UserPoolClient
(用作UserPoolId
)时,我无法引用UserPool
。
下列:
UserPoolId:
Ref: UserPool
产生错误:
变量 UserPoolId 的变量引用语法无效。 您只能引用环境变量、选项和文件。 您可以查看我们的文档以获取更多信息。
我不确定的另一件事是,我看到人们共享包含以下语法的 YAML:
UserPoolId: !Ref UserPool
但它也会失败和关于无效语法的错误(由于!Ref
)。 任何人都可以澄清我吗?
在离开计算机一段时间后,我认为问题可能出在其他地方,这就是这里的情况。
我在环境变量下使用${UserPoolId}
并意识到这就是问题所在。 我改为以下方式,问题解决了。 我没有正确引用用户池 ID(它引用了不存在的名为 UserPoolId 的 serverless.yml 局部变量)
userPoolId:
Ref: UserPool
这只是我的错误,现在已解决。
我发现在编写我的模板时,它有时会做不正确的语法突出显示,我必须编写它以便它无法检查。
参考:用户池
Fn::Sub: '${UserPool}'
通过与 Substitute 交换它,它无法检查字符串的内容是否有效,然后它将构造一个包含对 UserPool 的 Ref 或用户池 ID 的字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.