amazon-web-servicesaws-lambdayamlaws-cloudformation

Use macro inside CloudFormation Conditions


I've written a macro (called BucketChecker) that takes in an s3 bucket name and checks if it already exists. The fragment will return true or false accordingly.

I would like to use this macro in a Conditions section as described in this article: https://cloudnineapps.com/blogs/cloud-computing/how-to-create-dynamic-condition-expressions-in-aws-cloudformation-using-macros/.

The idea is to use this as a condition in my template like this:

Conditions:
  CreateBucket:
    Fn::Equals: ['false', 'Fn::Transform': {
      Name: BucketChecker,
      Parameters: {
        Operation: 'bucketExists',
        BucketName: 'my-bucket'
      }}]

Resources:
  MyBucket:
    Type: "AWS::S3::Bucket"
    Condition: CreateBucket   # -> only create it if doesn't yet exist
    Properties:      
      BucketName: 'my-bucket'

But cfn-linter gives me the error: E8003 Fn::Equals element must be a supported function (Ref, Fn::FindInMap, Fn::Sub, Fn::Join, Fn::Select, Fn::Split)

My main question is: is it even possible to achieve this using CloudFormation? If yes, what's wrong with my template? The linked article seems to be doing exactly the same, but mine doesn't work.


Solution

  • Based on the comments.

    The cfn-linter was incorrectly classifying the Fn::Transform as malformed.

    Deploying the stack confirmed that there are no issues with the Fn::Transform.