引用嵌套堆栈的输出 错误:"the attribute in Fn::ImportValue must not depend on any resources"



我有一个云形式模板,我在其中创建一个代码构造项目和与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

模板上的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

但是,这会导致以下错误:

模板包含错误:模板错误: fn :: importValue不得依赖任何资源,导入价值或 fn :: getazs

这是有道理的……VPCSTACK确实是一种资源。但是我如何避免这种情况?

这只是语法的东西,还是我需要以不同的方式构造我的模板才能完成?

我最终保留了现有的结构并使用此语法:

VpcConfig:
    VpcId: 
      Fn::GetAtt:
        - VpcStack
        - Outputs.VpcId

相关内容

最新更新