Nested stacks

随着CloudFormation声明的模块越来越多,多个模板可能经常用到同一个组件。Nested stack可以让重复的模块可以复用,被别的stack直接引用,例如负载均衡的属性或安全组的配置。

在使用Nested Stack时,通过AWS::CloudFormation::Stack类型来调用子的stack

Nested stack内部也可以嵌套其他Nested stack,形成多级结构:

             Nested stacks, which are created as part of another stack, have an immediate                 parent stack, and the top-level root stack.

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  myStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://s3.amazonaws.com/cfn-templates-us-east-1/S3_Bucket.template
      TimeoutInMinutes: '60'
Outputs:
  StackRef:
    Value: !Ref myStack
  OutputFromNestedStack:
    Value: !GetAtt myStack.Outputs.BucketName