amazon-web-services - CreateStack 操作:模板格式错误:模板的 Resources 块中未解析的资源依赖项 [VpcId]
问题描述
我正在使用多个 CF 模板,并打算跨模板导出和导入值。我很好地导出/导入了大多数值,但是在由于某种原因没有导入 VpcId 时遇到了这个问题。
第一个带有导出功能的模板
Parameters:
StackPrefix:
Type: String
Default: "app-name"
Outputs:
VpcId:
Value: !Ref VPC
Export:
Name: !Join [ ":", [ !Ref StackPrefix, VPC ] ]
第二个导入模板
Parameters:
StackPrefix:
Type: String
Default: "app-name"
Resources:
SecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: !Sub ${AWS::StackName}-alb
SecurityGroupIngress:
- CidrIp: "0.0.0.0/0"
IpProtocol: "TCP"
FromPort: 80
ToPort: 80
VpcId:
Fn::ImportValue: !Sub "${StackPrefix}:VPC"
部署模板aws cli
导致“模板验证错误”
aws --profile shiny-app cloudformation create-stack --stack-name app-elb --template-body file://02-load-balancer.yaml
An error occurred (ValidationError) when calling the CreateStack operation: Template format error: Unresolved resource dependencies [VpcId] in the Resources block of the template
任何帮助表示赞赏
解决方案
经过一个不眠之夜,跑过一位同事,我想回答我自己的问题
@Seth E 感谢您的意见,您说得对。
我在第 53-54 行有这个
53 VpcId:
54 Fn::ImportValue: !Sub "${StackPrefix}:VPC"
...在第 117 行,这出来了
117 VpcId: !Ref VpcId
我认为 CloudFormation 在很大程度上有助于识别模板中的哪一行有违规代码,但是对于这个错误,CloudFormation 对我来说不够清楚。在 CF 中调试(输出值不是那么直接),我认为这是我需要习惯于调试 CF 模板的东西。
An error occurred (ValidationError) when calling the CreateStack operation: Template format error: Unresolved resource dependencies [VpcId] in the Resources block of the template
推荐阅读
- graphql - 阿波罗解析器被称为两次?
- angular - 在两个 observables 完成后做一些事情
- python - Anaconda 中的 numpy 库
- sql - 如何更改 Postgres 10.2 中某列的默认排序?
- java - 获取 java 对象的调试信息
- python - Keras 损失似乎是错误的 - 加权和是错误的
- python - 使用 WALS 方法在 tensorflow 2.0 中进行矩阵分解
- java - 如何将spring bean注入休眠环境RevisionListener
- git - `是什么意思![拒绝] dev_tom -> dev_tom(非快进)* [新分支] dev_tom -> remote_repo/dev_tom`?
- python-3.x - 打印时如何在列表元素前面添加“+”或“-”