Introducing the template macro
First of all, macros are an optional part of CloudFormation. AWS already provides us with its own macros (AWS::Serverless
and AWS::Include
) – they are a part of CloudFormation and are executed whenever we use a Transform
block in a template or resource.
Custom macros (that is, macros created by us) are also part of the CloudFormation and are created as a resource with an AWS::CloudFormation::Macro
type. Each macro in particular is a Lambda function, which is similar to a custom resource, as it receives an event from CloudFormation and needs to return a response.
This Lambda function will receive a part of the template (or the full template), run custom processing, and return a transformed template.
The request from CloudFormation will look like the following:
{ «region»: «...», «accountId»: «...», «fragment»: {.....