Share Values upstream in a nested cloudformation stack possible?

两盒软妹~` 提交于 2019-12-14 03:08:07

问题


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 stack architecture. I could use cross-referencing with eXport/Import but would rather keep the nested stack if possible.


回答1:


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.



来源:https://stackoverflow.com/questions/52225797/share-values-upstream-in-a-nested-cloudformation-stack-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!