I have different Types of data flowing in through my kinesis streams. Each of the record has a different partition key. I need to invoke a lambda function only if a record with certain partition key in added to the stream. Is there a way to specify that the lambda would be triggered only if a partition key "a" is encountered rather than invoking a lambda and then checking the partition key?
2 Answers
It's more kind of a Design Question, I don't know if you can configure this. But you can always use Lambda Chaining using SNS.
Create SNS topic for each of your Partition Key and configure your Lambda on them respectively, then You can create one Parent Lambda function which can get Partition key and Object. And publish those object to the respective SNS topics.
You can either use an SNS topic where you push only records that have a certain partition key and then connect another lambda function to that topic that processes the records.
Another option would be to asynchronously re-invoke your lambda function. The benefit is that you don't need another component (i.e., no SNS topic).
How this would work is basically that you check in your function if the partition key is "a" and if it is, re-invoke the function asynchronously with the record and a specific parameter that indicates that the record should be processed.
You can read more about how this can be done here: https://engineering.dubsmash.com/implementing-real-time-analytics-using-aws-kinesis-lambda-1ea56f10e473