【发布时间】:2019-10-21 18:02:49
【问题描述】:
我正在使用多个 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
感谢任何帮助
【问题讨论】:
-
您确定模板中没有其他内容会导致此问题吗?只是为了测试,从 VpcID 中删除导入并对 VPC ID 进行硬编码。您是否还可以确认 VpcID 实际上是从第一个堆栈中正确导出的?
-
我不确定你指的是杯子。你在某处有
!Ref: VpcId吗?此外,为了调试您的第一个堆栈,您应该能够在 CloudFormation 控制台的“输出”选项卡中看到“导出名称”
标签: amazon-web-services yaml amazon-cloudformation