DEV Community

Kirk Kirkconnell
Kirk Kirkconnell

Posted on

AWS Lambda event filtering for Amazon DynamoDB Streams

On 26 Nov 2021, AWS released Lambda event filtering with Amazon DynamoDB as an event source. Some might flippantly say "meh, big deal." Well, if you use Lambda functions a lot and only care about a subset of the event in that DynamoDB stream, this really might be a big deal! So read on!!

Until this feature was released, your function(s) were invoked for each and every event on a DynamoDB stream. You could then have some if, case, etc. code to gauge if the event was something this function should care about and operate on. You paid for every invocation of your function. "Do I care about this event? yes. do this.", "Do I care about this event? No, drop it.", "Do I care about this event? yes. do this." and so on.

With the new event filtering, that filter is removed from your Lambda function code and moved up a level. Lambda itself absorbs the cost, both resource and cost wise, to watch the DynamoDB stream and if an event meets your filter, only then will your function be invoked. That is a massive and great change for us as AWS Lambda users. Let's say that you were invoking your function 200,000 time per day, but realistically less than 5% of the time was the event something the function would do something with. Now you'd only be invoking the function 10k times, instead of 200k, and thus only charged for that 10k invocations.

In addition to all of that, you just reduced the complexity of your code as you no longer have to code, maintain, and test that filtering functionality in your Lambda Function.

In summary, this is a great feature for customers that have AWS Lambda functions that need to operate only on a subset of events in a DynamoDB stream. Reduced code complexity, reduced cost, and so on. It is a win!

Discussion (2)

mwarkentin profile image
Michael Warkentin

This doesn't have any impact on the "2 simultaneous clients per stream" limitation on streams, does it?

nosqlknowhow profile image
Kirk Kirkconnell Author

This changes nothing when it comes to DynamoDB Streams, as event filtering is entirely a Lambda feature.