AWS Cloudformation Macro Getting Started

AWS has introduced cloudformation macro to write your own transformation of the template using Lambda

The above link describes it, but I was looking for a complete example to get started with.

Please follow the steps to get started with -

  1. Create python 3.6 lambda function with the following content

2. Create Transform Template — It is the same as serverless template

2. Deploy the Transform Template

aws cloudformation deploy — stack-name EchoMacro — template-file .\EchoMacro.yml — capabilities CAPABILITY_IAM

3. Create Template Transform — Utilize the above Transform Template to do the transformation of the whole template — in this case, lambda will echo only what it gets as fragment -

4. Deploy the Template Transform —

aws cloudformation deploy — stack-name EchoMacroTemplateTransform — template-file .\EchoMacroTemplateTransform.yml — capabilities CAPABILITY_IAM

5. View logs in Cloudwatch — /aws/lambda/EchoFunction to verify that lambda has echoed the fragment it has got -

6. Cleanup — Delete the stacks

aws cloudformation delete-stack — stack-name EchoMacroTemplateTransform
aws cloudformation delete-stack — stack-name EchoMacro

Hopefully the above will help to get started. Resource level transform can also be done by creating template and following the steps above. For more information, refer to -

Like what you read? Give Ripon Banik a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.