aws-cloudformation / cloudformation-coverage-roadmap

The AWS CloudFormation Public Coverage Roadmap
https://aws.amazon.com/cloudformation/
Creative Commons Attribution Share Alike 4.0 International
1.11k stars 54 forks source link

Received ''null' values are not allowed in templates'' while creating AWS::Events::Rule -> EventPattern #1378

Open rohan-1995 opened 1 year ago

rohan-1995 commented 1 year ago

Name of the resource

AWS::Events::Rule

Resource Name

No response

Issue Description

EventPattern accepts Null value as per EventBridge service [1] ,even CDK documentation [2] mention that EventPattern can have null values. However CloudFormation service does not accept Null value when defined for EventPattern. Template fails in validation with following error - 'null' values are not allowed in templates

[1] https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns-null-values.html [2] https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_events.EventPattern.html

Expected Behavior

AWS::Events::Rule should accept null values for 'EventPattern' property

Observed Behavior

template does not pass validation and throws error - 'null' values are not allowed in templates

Test Cases

Create EventBridge rule with EventPattern having null value in CFN template

Other Details

No response

minne6 commented 4 months ago

Hi, Do you have any solution for this problem? Is this fixed? I am unable to use null check in eventbridge pattern using yaml cloudformation template. @rohan-1995

slootjes commented 2 weeks ago

Almost 2 years later, this is still an issue.

slootjes commented 2 weeks ago

My colleague had a brilliant hacky idea and it seems to work. Since the property EventPattern is a JSON type, it also supports a stringified JSON object, where null values are allowed.

YourRule:
  Type: AWS::Events::Rule
  Properties:
      EventPattern: '{
          "detail": {
             "responseElements": [null]
          }
        }'

It doesn't look pretty but it does the trick :)