I am using AWS CloudFormation to configure EventBridge Rules to direct events to different SQS queues depending on their contents.
For example:
{
"detail": {
"data": {...},
"metadata": {
"api_version": "1",
"some_other_field": "whatever"
}
}
}
Or:
{
"detail": {
"data": {...},
"metadata": {
"some_other_field": "whatever"
}
}
}
In the first case the event will be sent to the version 1 API, and in the second case the event should also be sent to the version 1 API by default since it is not defined. I should be able to configure this by specifically matching against the null
value as specified in the docs, however I can’t use that functionality because CloudFormation does not allow null values anywhere in the stack. So I was going to define the rules like this:
Resources:
ExampleRule1:
Type: AWS::Events::Rule
Properties:
Description: "..."
EventBusName: "..."
EventPattern:
detail.metadata:
- api_version: 1
- some_other_field: "whatever"
Name: "..."
RoleArn: "..."
State: "..."
Targets:
- "version 1 target"
ExampleRule2:
Type: AWS::Events::Rule
Properties:
Description: "..."
EventBusName: "..."
EventPattern:
detail.metadata:
- api_version: 2
- some_other_field: "whatever"
Name: "..."
RoleArn: "..."
State: "..."
Targets:
- "version 2 target"
ExampleRuleDefault:
Type: AWS::Events::Rule
Properties:
Description: "..."
EventBusName: "..."
EventPattern:
detail.metadata:
# Remove the version rule so it matches
# when the api_version is missing
- some_other_field: "whatever"
Name: "..."
RoleArn: "..."
State: "..."
Targets:
- "version 1 target"
However this documentation suggests that missing values are treated as "*": "*"
which would seem to imply that if someone sent api_version: 2
then there is a possibility that ExampleRuleDefault
could capture it. I couldn’t find any reference for what the behavior would be, so I am unsure that this is an acceptable solution.
So my question is, how can I define the rules of to capture events missing that value and not capture other events? (ps. requiring the api_version
field is not an option)