在嵌套堆栈中访问父级Cloudformation堆栈的名称

use*_*942 3 amazon-s3 amazon-web-services aws-cloudformation

我正在使用结构如下的嵌套Cloudformation模板:

masterTemplate-> childA-> childB

每个JSON模板文件都存储在S3中,其存储桶名称为“ $ {masterStackName} -env-upload”。从父模板可以正常工作,就像我可以做的那样:

"TemplateURL":  {
          "Fn::Join": [
            "",
            [
              "https://s3.amazonaws.com/",
              {
                "Ref": "AWS::StackName"
              },
              "-env-upload/device-specific-template-HALO-BUILD-VERSION.json"
            ]
          ]
        },
Run Code Online (Sandbox Code Playgroud)

但是,当childA尝试执行相同的操作来启动childB模板时,“ AWS :: StackName”将成为childA的生成名称-表示它正在尝试访问不存在的存储桶。

我的问题是:如何将主/父堆栈的名称传递给子堆栈?我尝试将其作为参数来执行,但是参数值不允许使用“ Ref”(因此,我无法为该值执行“ Ref”:“ AWS :: StackName”)。

任何帮助表示赞赏!

Lau*_*ard 6

实际上,可以使用参数将父堆栈名称传递给子堆栈:

这是一个例子:

parent.yml

---
AWSTemplateFormatVersion: '2010-09-09'
Resources:
  ChildA:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: ...test/test-child-a.yml
      Parameters:
        ParentStackName: !Ref AWS::StackName
Run Code Online (Sandbox Code Playgroud)

测试子a.yml

---
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  ParentStackName:
    Type: String
Resources:
  TestBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref ParentStackName
Run Code Online (Sandbox Code Playgroud)