Is there a way to enumerate all CloudFormation Macros created in an AWS Account?

242 Views Asked by At

There doesn't appear to be any way in the console or the CLI to enumerate macros that have get created. They can be referenced by name in any other stack template, so clearly, they're being stored in an account-global registry, but it doesn't look like it's exposed.

Having a library of macros is a powerful thing, but if they are going to be shared with others on team sharing an account then there needs to be a discovery process. Is the expectation that name/usage information is published externally?

Obviously enough, Macros are even more powerful when they can be shared across an entire organization. Stack sets can be used to do that, so I guess a master stack set could also create a documentation resource of some kind.

Seems irksome not to be able to enumerate Macros like lots of other things, including the more exotic extensions that can be registered. Am I missing something?

I've searched the AWS documentation and spent lots of time searching the web and can't find anybody talking about it. That either means I'm missing something easy and obvious, it's not particularly important to enough folks, or nobody wants to be the first to ask.

1

There are 1 best solutions below

0
Paolo On

The AWS::CloudFormation::Macro resource is effectively a wrapper around a lambda function as described in the documentation. And while AWS::CloudFormation::Macro is a CloudFormation resource, there is no such thing as a macro resource in AWS.

So in order to list all of the macro functions in your account you have two options:

  1. Use the aws cloudformation get-template CLI command for each of your templates, then parse them to check whether AWS::CloudFormation::Macro exists
  2. Use the aws lambda get-function CLI command for each of your lambda functions, then check whether a certain tag (e.g. Macro:True) exists or not. This approach requires you to properly tag these lambda functions.