yaml 中的 Cloudformation 嵌套堆栈输出

Cloudformation nested stack outputs in yaml

在我的嵌套堆栈中,我需要使用输出值和 AWS::CloudFormation::Stack returns 值作为

Fn::GetAtt Outputs.NestedStackOutputName

但是 yaml 不允许我使用

!GetAtt MyResourceName.Outputs.MyOutputName

因为它试图将它们分成 3 块而不是它需要的 2 块。

我也试过用

Value: "Fn::GetAtt": [ "MyResourceName", "Outputs.MyOutputName" ] 

但后来我得到

mapping values are not allowed here
  in "<string>", line 21, column 24:
        Value: "Fn::GetAtt": [ "MyResourceName", "Outputs.MyOutputName" ]

那么我应该如何使用它呢?我真的必须为此切换到 json 吗?

使用这两个堆栈对我有用:

root.yml:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  MyNestedStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://s3.amazonaws.com/spg-test-bucket/cloudformation/nested.yml?versionId=HqlgDnuntMzkmK0398GPdJRUXMN_PMdn
  RootBucket:
    Type: AWS::S3::Bucket
    Properties:
      LoggingConfiguration:
        DestinationBucketName:
          Fn::GetAtt: [MyNestedStack, Outputs.NestedBucket]

nested.yml:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  DataBucket:
    Type: AWS::S3::Bucket
    Properties:
      AccessControl: LogDeliveryWrite
Outputs:
  NestedBucket:
    Value:
      Ref: DataBucket

您的问题是由 known bug in aws-cli's custom YAML-parsing code that was added recently as part of the aws cloudformation deploy and aws cloudformation package 命令引起的。

此问题已在 aws-cliversion 1.11.37 中修复。要解决此问题,您可以执行以下任一操作:

  • aws-cli 升级到版本 1.11.37 或更高版本。
  • 如果您不使用本地工件,请使用 aws cloudformation [create|update]-stack 来 create/update 您的堆栈而不是 aws cloudformation [package|deploy]