Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Lambda function be automatically called when a MySQL (RDS) table has a row created/updated?

DynamoDB has a feature called "Streams", which can automatically call a Lambda function whenever a table row is created or updated.

Is there a way to implement this with RDS (MySQL) and Lambda? I would love it if a Lambda function could be called when a row is created or updated.

I know it's possible to poll the database for table/row changes, but I'd rather have the Lambda be triggered from an external event. I also read about RDS Events and using SNS to subscribe to these events. But these RDS Events seem like operational events (Availability, Configuration, Recovery). There are no "events" for data changes.

like image 359
Chris Avatar asked Oct 31 '22 05:10

Chris


1 Answers

At the time of writing there is no easy way to do this. RDS doesn't track actual SQL actions and MySQL doesn't know how to interface with Lambda.

That said, if you take a look at this relevant SO thread (Send an http request in mysql trigger after insertion in a table) it explains how to perform and HTTP request.

Now, if you have a lambda function behind API Gateway and perform an HTTP request, you might be able to accomplish what you want, but [without knowing the application], I would ask whether it would be easier to update your application to trigger the lambda functions itself.

like image 143
Lorenzo Aiello Avatar answered Nov 12 '22 23:11

Lorenzo Aiello