MAK
MAK

Reputation: 2283

AWS CloudFormation Macros are not invoked while deleting Stacks. They are invoked only while creating/updating Stacks

I have cloned this repo and deployed the Count stack successfully.

https://github.com/awslabs/aws-cloudformation-templates/blob/master/aws/services/CloudFormation/MacrosExamples/Count/template.yaml

The macro function (CountMacroFunction) is invoked when I deploy Count-test stack (test.yaml).

May I know how to invoke this macro when I delete the stack please?

Upvotes: 0

Views: 263

Answers (1)

matt helliwell
matt helliwell

Reputation: 2678

Because Count is a macro, not a custom resource. A macro is a preprocessor for the Cloudformation template. It takes the template, changes it and outputs a new template. Cloudformation then carries on creating the stack using the updated template.

When you delete the stack, it deletes all resources defined in the stack so there is no need to call the macro again.

In contrast a custom resource is executed at deployment and is used to control resources that Cloudformation doesn't support or to implement other custom logic. The custom resource will be invoked when the stack is deleted to give it a chance to clear up the resources it created.

Upvotes: 1

Related Questions