我有一个 CloudFormation 模板,在其中创建 CodeBuild 项目和 VPC 相关资源的嵌套堆栈。以下是摘录:
Resources:
VpcStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: https://s3-eu-west-1.amazonaws.com/foo-bar/vpc/vpc.template.json
CustomCodeBuild:
Type: AWS::CodeBuild::Project
Properties:
... other properties
VpcConfig:
VpcId:
Fn::ImportValue: !Sub ${VpcStack}:VpcId
TemplateURL 处的 VPC 模板如下摘录所示:
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
... various properties
Outputs:
VpcId:
Value: !Ref VPC
Export:
Name: !Sub ${AWS::StackName}:VpcId
如您所见,我正在尝试从嵌套堆栈导入 VpcId。
VpcConfig:
VpcId:
Fn::ImportValue: !Sub ${VpcStack}:VpcId
但是,这会导致以下错误:
Template contains errors.: Template error: the attribute in Fn::ImportValue must not depend on any resources, imported values, or Fn::GetAZs
这是有道理的……VpcStack确实是一种资源。但我该如何避免这种情况呢?
这只是一个语法问题,还是我实际上需要以不同的方式构建我的模板才能实现这一目标?
最佳答案
我最终保留了现有的结构并使用了以下语法:
VpcConfig:
VpcId:
Fn::GetAtt:
- VpcStack
- Outputs.VpcId
关于amazon-web-services - 引用嵌套堆栈的输出错误: "the attribute in Fn::ImportValue must not depend on any resources",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53820497/