引用嵌套堆栈的输出错误:“ Fn :: ImportValue中的属性不得依赖任何资源”

时间:2018-12-17 17:44:47

标签: amazon-web-services amazon-cloudformation

我有一个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

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

  

模板包含错误。:模板错误:中的属性   Fn :: ImportValue不得依赖任何资源,导入的值或   Fn :: GetAZs

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

这只是语法问题,还是我需要以不同的方式实际构造模板以实现此目的?

1 个答案:

答案 0 :(得分:0)

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

VpcConfig:
    VpcId: 
      Fn::GetAtt:
        - VpcStack
        - Outputs.VpcId
相关问题