Skip to content

aws-events: Support 'null' values for event matching #8660

Open
@homanchou

Description

@homanchou

I'm trying to use AWS CDK to create an eventbridge rule.

The custom event will have a detail payload where I only want to match on events where order_item_id is null.

Here is the rule in cdk:

rule.addEventPattern({
  account: ['xxxxxxxxx'],
  detailType: ['inventory_adjusted'],
  detail: {
    'order_item_id': [null]
  }
})

And according to aws documentation, this is allowed:

https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html

To match events where the value of responseElements is null, use the following pattern, which would match the event example.
{ "detail": { "responseElements": [null] } }

However, when deploying with cdk I get this error:

development failed: ValidationError: [/Resources/sendinventoryadjustmentstolambda8954C2E5/Type/EventPattern/detail/order_item_id/0] 'null' values are not allowed in templates >[/Resources/sendinventoryadjustmentstolambda8954C2E5/Type/EventPattern/detail/order_item_id/0] 'null' values are not allowed in templates

And here is the cdk synth for the area around the rule:

EventPattern:
    account:
      - "xxxxxxxxx"
    detail-type:
      - inventory_adjusted
    detail:
      order_item_id:
        - null

Indeed it is null... which apparently isn't allowed in yaml template, but then how do I express this in CDK?

Reproduction Steps

create a rule that tries to match a null value for detail key

rule.addEventPattern({
  account: ['xxxxxxxxx'],
  detailType: ['inventory_adjusted'],
  detail: {
    'order_item_id': [null]
  }
})

Error Log

development failed: ValidationError: [/Resources/sendinventoryadjustmentstolambda8954C2E5/Type/EventPattern/detail/order_item_id/0] 'null' values are not allowed in templates >[/Resources/sendinventoryadjustmentstolambda8954C2E5/Type/EventPattern/detail/order_item_id/0] 'null' values are not allowed in templates

Environment

  • **CLI Version :
cdk --version
1.45.0 (build 0cfab15)
  • Framework Version:
  • **Node.js Version:
node -v
v11.15.0
  • **OS : osX 10.14.6
  • **Language (Version): typescript

Other


This is 🐛 Bug Report

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-eventsRelated to CloudWatch Eventseffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.needs-cfnThis issue is waiting on changes to CloudFormation before it can be addressed.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions