What Macros Do

What a Macro Does to a Template Fragment

A macro is a Lambda 24 function registered under a name. CloudFormation 24 sends it a piece of the template, the fragment, and puts whatever it returns in that piece's place. Named in the top-level Transform section, a macro receives the whole template; named in Fn::Transform: {Name: ..., Parameters: {...}}, it receives the siblings of that call, such as one resource's other properties, plus the Parameters as params.

The event also carries requestId, accountId, region and templateParameterValues; the function returns requestId, status (success, or anything else with an errorMessage) and the new fragment. The most deeply nested macros run first, and intrinsic functions are resolved only afterwards, so a macro sees {"Ref": "Stage"}. Macros do not run recursively, and work only in the account and region where they are registered. A direct deploy needs CAPABILITY_AUTO_EXPAND; AWS 24 advises a change set, whose Processed template shows the result.