aws / aws/aws-cdk

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

Open
#8,660 6 comments 6 reactions 0 assignees View on GitHub
@aws-cdk/aws-events effort/small feature-request needs-cfn p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

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: Bug Report

Contributor guide

Open the contributing guide

Research direction

Start with the TypeScript rule.addEventPattern call and the synthesized EventPattern shown in the report. Trace how the detail.order_item_id value reaches template validation, then compare the behavior with the AWS event-pattern documentation. Done means a null matcher can be synthesized and deployed without the reported validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.