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

标签 amazon-web-services aws-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

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

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/

相关文章:

amazon-web-services - 在Amazon ECS上运行Docker镜像

amazon-web-services - 如何在cloudformation中自引用SourceSecurityGroup?

amazon-web-services - 如何从 CloudFormation 模板中的相同 AWS 角色承担 AWS 角色?

amazon-web-services - 无权执行 : dynamodb:Scan Lambda

python-3.x - 使用 livy 向 AWS EMR 提交具有虚拟环境的 pyspark 作业

python-3.x - 自定义资源 CloudFormation 来标记事件规则

node.js - 无服务器 : Deploy to same api from different yml

aws-cloudformation - 无服务器环境变量范围

spring - 如何将Spring Boot RESTful Web服务Docker镜像部署到EC2?

xml - AWS API 网关接受内容类型 : application/xml