![](/img/trans.png)
[英]Is it possible in CloudFormation to share Conditions definition across nested stack?
[英]Share Values upstream in a nested cloudformation stack possible?
有什么方法可以将值从子堆栈传递到父堆栈吗? 我发现的只是向下传递值,但从不向上传递值,不幸的是,这与我的堆栈架构不符。 我可以使用 eXport/Import 的交叉引用,但如果可能的话,我宁愿保留嵌套堆栈。
您绝对可以从子堆栈中收集输出值并在父堆栈中使用它们。
例如:
# 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
在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.
要记住的棘手事情是在引用AWS::CloudFormation::Stack
时添加Outputs
。
请注意,这将使SomeOtherResource
依赖于SomeChildStack
,因此在创建SomeChildStack
之前不会创建SomeOtherResource
。
我们遇到了同样的问题,并且接受的答案(使用.Ref)没有用。 CloudFormation 不会部署堆栈。
对我们有用的是:
!GetAtt [NestedStack, Outputs.MyOutput]
父堆栈:
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]
嵌套堆栈:
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.