I'm interested in value changes of a specific (numeric) field/column (say "count") of a DynamoDB table.
I know that I could write a Lambda that, once triggered, compares the new image with the old one and then decides whether it is the case of actually doing something or not. But, since my table collects a sort of status updates and only a few of them are actually significant for my trigger, in such a setting, the Lambda would be invoked pointlessly most of the times (and, moreover, I would be charged money for having invoked the Lambda).
So I want to filter the DynamoDB Stream events and, according to the docs, it should be possible (even if no example for similar cases is given).
My problem is that I cannot find how to write the equivalent of OldImage['count'] != NewImage['count'] in the filter pattern.
Here is an example of how this part of my SAM template should appear.
CountChangeDetector:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: src/
Handler: trigger.lambda_handler
Runtime: python3.8
FunctionName: "CountChangeDetector"
AutoPublishAlias: live
Events:
Stream:
Type: DynamoDB
Properties:
Stream: !GetAtt MyTable.StreamArn
BatchSize: 10
StartingPosition: TRIM_HORIZON
FilterCriteria:
Filters:
- Pattern: '{"OldImage": {"count": [ { "anything-but": [ {"NewImage": {"count"}} ] } ]}}'
Of course, the way I've defined the pattern is incorrect and I get an error.
So, how shall the pattern be defined?