我正在尝试设置新的存储库,但不断出现错误
The CloudFormation template is invalid: Template error: instance of Fn::GetAtt
references undefined resource uatLambdaRole
在我的理想阶段,但是格式完全相同的开发阶段效果很好。
对于每种环境,我都有一个资源文件。
dev
devLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: dev-lambda-role # The name of the role to be created in aws
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaFullAccess
#Documentation states the below policy is included automatically when you add VPC configuration but it is currently bugged.
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
燕麦
uatLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: uat-lambda-role # The name of the role to be created in aws
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaFullAccess
#Documentation states the below policy is included automatically when you add VPC configuration but it is currently bugged.
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
在我的serverless.yml
中,我的角色定义为
role: ${self:custom.stage}LambdaRole
并将舞台设置为
custom:
stage: ${opt:stage, self:provider.stage}
运行serverless deploy --stage dev --verbose
成功,但是运行serverless deploy --stage uat --verbose
失败,并显示错误。谁能看到我在做什么错?直接从开发人员那里复制了uat资源,只更改了阶段名称。
答案 0 :(得分:0)
我错过了将配置的关键部分复制到我的资源文件的实际参考中
resources:
Resources: ${file(./serverless-resources/${self:provider.stage}-resources.yml)}
问题是我复制了指南中的内容,并熟练使用了self:provider.stage
而不是self:custom.stage
。当我更改此设置后,便可以部署它。
答案 1 :(得分:0)
在此处结束时出现相同的错误消息。我的问题最终是我倒退了serverless.yml
中的“资源”和“资源”键。
正确:
resources: # <-- lowercase "r" first
Resources: # <-- uppercase "R" second
LambdaRole:
Type: AWS::IAM::Role
Properties:
...
?♂️