Share Values upstream in a nested cloudformation stack possible?

后端 未结 1 2071
情书的邮戳
情书的邮戳 2021-01-28 23:01

Is there some way to pass on Values form a child stack to a parent stack? All I found was to pass values down, but never up, that would unfortunately not correspond with my stac

相关标签:
1条回答
  • 2021-01-28 23:14

    You can definitely gather outputed values from a child stack and use them in the parent stack.

    For example:

    # parent stack
    AWSTemplateFormatVersion: 2010-09-09
    Resources:
      SomeChildStack:
        Type: AWS::CloudFormation::Stack
        Properties:
          Parameters:
            AWS CloudFormation Stack Parameters
          TemplateURL: !Ref SomeTemplateUrl
    
      SomeOtherResource:
        Type: AWS::AnyOther::Resources
        Properties:
          SomeProperty: !Ref SomeChildStack.Outputs.MyOutput
    

    And in SomeChildStack:

    # The template used for SomeChildStack
    AWSTemplateFormatVersion: 2010-09-09
    Resources:
      S3Bucket:
        Type: AWS::S3::Bucket
        Properties:
          AccessControl: PublicRead
          LoggingConfiguration:
            DestinationBucketName: !Ref 'LoggingBucket'
            LogFilePrefix: testing-logs
    Outputs:
      MyOutput:
        Value: !Ref 'S3Bucket'
        Description: Name of the sample Amazon S3 bucket.
    

    The tricky thing to remember is adding the Outputs when referencing the AWS::CloudFormation::Stack.

    Note that this will make SomeOtherResource depend on SomeChildStack, so SomeOtherResource won't be created until SomeChildStack has been created.

    0 讨论(0)
提交回复
热议问题