I am trying to filter a DynamoDB stream via EventBridge patterns, I would like to be able to filter based on a value in specific column that can change for two reasons:
- A new row was inserted with the specific value I am looking for.
- An existing role’s value was changed to the desired value.
Any other changes should be ignored. I tried creating following filter:
{
"eventName": ["INSERT", "MODIFY"],
"dynamodb": {
"NewImage": {
"state": {
"M": {
"column": {
"S": ["state1"]
}
}
}
},
"OldImage": {
"state": {
"M": {
"column": {
"S": [{
"anything-but": ["state1"]
}]
}
}
}
}
}
}
This of course fails because create operations do not have OldImage entries. Looking at the AWS documentation for conditional matches I then tried to add an $or statement with null and a valid OldImage entry but it it not considered to be a valid EventBridge:
"OldImage": {
"$or" : [null, {....}]
}
Aside from simply creating a lambda that checks the OldImage vs the NewImage is there a way to achieve this via EventBridge filters?
2
Answers
When you apply 2 filters together they become a Boolean AND expression. You want to acbibeia Boolean OR, so you should create 2 individual filters. You can attach up to 5 filters to a DynamoDB stream.
I think this would work