[英]Unable to reference CloudFormation resource in serverless.yml. Invalid variable reference syntax for variable UserPoolId
I am using the Serverless framework to deploy a serverless app to AWS.我正在使用无服务器框架将无服务器应用程序部署到 AWS。 However, the CloudFormation part is not working as expected.
但是,CloudFormation 部分没有按预期工作。 I have looked up on the web and couldn't find anything wrong with my YAML.
我在网上查了一下,没有发现我的 YAML 有什么问题。
I am creating a UserPool
and then UserPoolClient
by using CloudFormation.我正在创建一个
UserPool
,然后使用UserPoolClient
创建UserPool
。 I have the following YAML for resources:
我有以下 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"
I am unable to reference UserPool
when specifying UserPoolClient
(to be used as UserPoolId
).指定
UserPoolClient
(用作UserPoolId
)时,我无法引用UserPool
。
The following:下列:
UserPoolId:
Ref: UserPool
yields the error:产生错误:
Invalid variable reference syntax for variable UserPoolId.
变量 UserPoolId 的变量引用语法无效。 You can only reference env vars, options, & files.
您只能引用环境变量、选项和文件。 You can check our docs for more info.
您可以查看我们的文档以获取更多信息。
Another thing which I am not sure about, I have seen people sharing YAML containing the following syntax:我不确定的另一件事是,我看到人们共享包含以下语法的 YAML:
UserPoolId: !Ref UserPool
But it also fails and errors about the invalid syntax (due to !Ref
).但它也会失败和关于无效语法的错误(由于
!Ref
)。 Can anyone clear me on this?任何人都可以澄清我吗?
After taking some time off the computer, I thought that the problem could be somewhere else which is what the case here.在离开计算机一段时间后,我认为问题可能出在其他地方,这就是这里的情况。
I was using ${UserPoolId}
under environment variables and realized that this is where the problem lies.我在环境变量下使用
${UserPoolId}
并意识到这就是问题所在。 I changed to the following way and the problem got solved.我改为以下方式,问题解决了。 I was not referencing user pool ID correctly (it was referencing serverless.yml local variable named UserPoolId which didn't exist)
我没有正确引用用户池 ID(它引用了不存在的名为 UserPoolId 的 serverless.yml 局部变量)
userPoolId:
Ref: UserPool
This was just my mistake and is now solved.这只是我的错误,现在已解决。
I found whilst writing my template it sometimes would do incorrect syntax highlighting and I would have to write it so that it couldn't check.我发现在编写我的模板时,它有时会做不正确的语法突出显示,我必须编写它以便它无法检查。
Ref: UserPool参考:用户池
Fn::Sub: '${UserPool}' Fn::Sub: '${UserPool}'
By swapping it with Substitute, it cannot check that the contents of the string are valid and then it will construct a string containing the Ref to the UserPool, or the user pool id通过与 Substitute 交换它,它无法检查字符串的内容是否有效,然后它将构造一个包含对 UserPool 的 Ref 或用户池 ID 的字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.