I have set up Dynamo table and have enabled stream and also enabled TTL (timetolive) on one of the columns. I also have one lambda which will pull entry from Dynamo Stream.
Now either I add, delete, or edit, Or TTL gets expired - all this will cause the lambda invocation.
I am not interested in add or edit event, I only want stream to receive the deleted, TTL expired entries, is this possible?
Also, I can definitely put a check in my lambda code and process only when event type of "delete", but still lambda invocation for add, edit will take place regardless. Kindly guide
You can't control DynamoDB stream, it will always post events for any changes happened to your table, however you can control the lambda invocation by adding property "FilterCriteria" in your "EventSourceMapping"
https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html
FilterCriteria: {"Filters": [{"Pattern": "{ \"userIdentity\": { \"type\": [ \"Service\" ] ,\"principalId\": [\"dynamodb.amazonaws.com\"] }}"}]}
using above filter your lambda will be only invoked if TTL expiry event posted in the DymnamoDB stream.
Sadly, you can't make DynamoDB stream, to stream only deletion or expiration of items. Everything is streamed, and its up to your lambda function to filter the events of interests.
For TTL expired items, your function needs to check:
"userIdentity":{
"type":"Service",
"principalId":"dynamodb.amazonaws.com"
}
An alternative way, is to have second table, only with TTL markers. This could be useful, if your primary table experiences a lot of updates and modifications. This way, the stream on your second table would only invoke your function twice for each item, i.e. creation and TTL expiration, rather then for all the updates you are not interested in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With