0
votes

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
Wouldn't that create some sort of circular reference between your stacks? Each one will have to be deployed for the other one to import the value - yorodm
I Tried @aerioeus way but not worked! Then i changed !Ref by !GetAtt its worked! !GetAtt [SomeChildStack, Outputs.MyOutput] - デゥック

1 Answers

0
votes

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.