AWS::Include transform - AWS CloudFormation (original) (raw)

This topic describes how to use the AWS::Include transform to insert boilerplate content into your CloudFormation templates.

The AWS::Include is a CloudFormation macro that, when referenced in your stack template, inserts the contents of the specified file at the location of the transform in the template when you create or update a stack using a change set. The AWS::Include function behaves similarly to an include, copy, or import directive in programming languages.

Usage

You can use the AWS::Include transform anywhere within the CloudFormation template except in the template parameters section or the template version. For example, you can use AWS::Include in the mappings section.

Syntax at the top level of a template

To declare this transform at the top level of your CloudFormation template, as theTransform section, use the following syntax:

JSON

{
  "Transform":{
    "Name":"AWS::Include",
    "Parameters":{
      "Location":"s3://amzn-s3-demo-bucket/MyFileName.json"
    }
  },
  "Resources":{
    ...
  }
}

YAML

Transform:
  Name: 'AWS::Include'
  Parameters:
    Location: 's3://amzn-s3-demo-bucket/MyFileName.yaml'
Resources:
  ...

Syntax when the transform is embedded within a section of a template

To declare this transform within a section of your CloudFormation template, use theFn::Transform intrinsic function and the following syntax:

JSON

{
  "Fn::Transform":{
    "Name":"AWS::Include",
    "Parameters":{
      "Location":"s3://amzn-s3-demo-bucket/MyFileName.json"
    }
  }
}

YAML

'Fn::Transform':
  Name: 'AWS::Include'
  Parameters:
    Location: s3://amzn-s3-demo-bucket/MyFileName.yaml

For more information, see Fn::Transform.

Parameters

Location

The location is an Amazon S3 URI, with a specific file name in an S3 bucket. For example,s3://`amzn-s3-demo-bucket`/`MyFile.yaml`.

Considerations

When using AWS::Include, keep the following considerations in mind. For more considerations about using macros, see Macros considerations in the AWS CloudFormation User Guide.

Examples

The following examples show how to use the AWS::Include transform to execute a wait condition handle. Replace amzn-s3-demo-bucket with your actual bucket name.

First, save a YAML file named single_wait_condition.yaml in your S3 bucket with the following contents:

MyWaitCondition:
  Type: AWS::CloudFormation::WaitCondition
  Properties:
    Handle: !Ref MyWaitHandle
    Timeout: '4500'

You can then reference this file using either JSON or YAML format.

JSON

{
   "Resources": {
      "MyWaitHandle": {
         "Type": "AWS::CloudFormation::WaitConditionHandle"
      },
      "Fn::Transform": {
         "Name": "AWS::Include",
         "Parameters": {
            "Location": "s3://amzn-s3-demo-bucket/single_wait_condition.yaml"
         }
      }
   }
}

YAML

Resources:
  MyWaitHandle:
    Type: AWS::CloudFormation::WaitConditionHandle
  'Fn::Transform':
    Name: 'AWS::Include'
    Parameters:
      Location: "s3://amzn-s3-demo-bucket/single_wait_condition.yaml"

For more information, see Create wait conditions in a CloudFormation template in the AWS CloudFormation User Guide.