The Key Difference Between Knowledge and Wisdom

Ever since we are kids all the way up to age 18 when one usually finishes high school, we’re spoon-fed most of our learnings. Teachers at school give us the basics of math, science, language…


Dynamic resource generation of resources using CloudFormation Macros.

One of the things you can do with this new feature is generate and deploy a number of resources based in a parameter value or the resulting value of the describing the number of AZs in order to create a subnet for each AZ for example.

In this example I’m defining a dynamic number of IAM users (depending on the int I provide in the parameter) that will have the same custom EC2 policy for EC2 resources tagged with Owner:devteam. The user will be prompted to reset their passwords on next sign-in. Also an EC2 instance will be created for each user simulating a classroom.

How to work with Macros:

In order to use this feature you need two things:

-One stack containing a AWS::CloudFormation::Macro resource along a “AWS::Lambda::Function”.

-The stack that will use the Macro which will process a section or the whole template by using on it the Fn::Transform function or a Transform section to transforming the whole template.

Biggest Caveat:

- Your Function will receive the whole template minus transform sections.

Take care of how you send the Macro Response in your lambda function.
You need to send the proper “Fragment”, this is the the processed template CFN receive from the lambda function.

In the sample attached I’m using python and just looping to create the number of resources I need in the final template. However you can go further with your function and implement more complex logics using the SDK to do API describes etc…

You can keep several Macros in your account doing different types of processing and using them whenever you need unlimited power to process your template suiting to a huge amount of use cases.


Macro Template:

Template to be processed:

Add a comment

Related posts:

What exactly is a gramathana site?

What exactly is a gramathana site? Is it a legal site to buy? Do we get loan for buying such a site from banks? Thanks in advance. Answer : I might suggest you to visit this web page where you can… Read more

Chapter 1

A dry tumbleweed rolled across the dusty desert plain, indifferently ambling over the emotionless face of an armadillo. The animal gave no response, parched and mummified as it was. What started as a… Read more

How Does Ethereum Work?

Ethereum is a platform on which anyone can build unstoppable¹, decentralised applications. If you have never heard of Ethereum or if you don’t know what it can be used for, I would strongly recommend… Read more