简体   繁体   English

在嵌套的 cloudformation 堆栈中上游共享值可能吗?

[英]Share Values upstream in a nested cloudformation stack possible?

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.我可以使用 eXport/Import 的交叉引用,但如果可能的话,我宁愿保留嵌套堆栈。

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 :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 .要记住的棘手事情是在引用AWS::CloudFormation::Stack时添加Outputs

Note that this will make SomeOtherResource depend on SomeChildStack , so SomeOtherResource won't be created until SomeChildStack has been created.请注意,这将使SomeOtherResource依赖于SomeChildStack ,因此在创建SomeChildStack之前不会创建SomeOtherResource

We had the same issue and the accepted answer (using.Ref) didn't work.我们遇到了同样的问题,并且接受的答案(使用.Ref)没有用。 CloudFormation wouldn't deploy the stack. CloudFormation 不会部署堆栈。

What did work for us is:对我们有用的是:

!GetAtt [NestedStack, Outputs.MyOutput]

Parent stack:父堆栈:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  NestedStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: !Ref NestedStackTemplateUrl

  ResourceInParentStack:
    Type: AWS::AnyOther::Resources
    Properties:
      SomeProperty: !GetAtt [NestedStack, Outputs.MyOutput]

Nested stack:嵌套堆栈:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  S3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: 'MyBucketName'
      ...

Outputs:
  MyOutput:
    Value: !Ref S3Bucket
    Description: Name of the sample Amazon S3 bucket.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM