Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure dynamoDb stream to invoke lambda function only on delete

I have configured a lambda function to take DynamoDb Stream as trigger. It seems to pick up all events on the DynamoDb

Is there any options to invoke Lambda only on certain type of event ( DynamoDB item delete ) so that Lambda function will not be fired on every action?

The goal is to save the cost of invoking lambda function for events that I dont need.

like image 438
qkhanhpro Avatar asked May 27 '18 09:05

qkhanhpro


2 Answers

There is no such options as far as I know. DynamoDB updates its stream data whenever any item is created, modified and deleted. Any change in the stream invokes the lambda function. You can check for "eventName" value as "REMOVE" in the event from dynamodb and only process that event.

like image 168
Manoj Acharya Avatar answered Nov 15 '22 00:11

Manoj Acharya


There is now a way to do that,

https://aws.amazon.com/blogs/compute/filtering-event-sources-for-aws-lambda-functions/

It's a new feature of lambda, it uses the same syntax as AWS Eventbdridge.

aws lambda create-event-source-mapping \
--function-name fleet-tire-pressure-evaluator \
--batch-size 100 \
--starting-position LATEST \
--event-source-arn YOUR_DB_STREAM_ARN \
--filter-criteria '{"Filters": [{"eventName": ["EventA"]}]}'

You can refer to this documentation to know the exact syntax

like image 23
Anirudh Avatar answered Nov 15 '22 00:11

Anirudh