Home > Net >  AWS RDS notification when record is added to a table
AWS RDS notification when record is added to a table

Time:09-27

Is this possible?

I did my research but this is the only possible events for RDS:

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Events.Messages.html

Mostly for maintenance type events but what I want is - let's I have a RDS Oracle table called Users. Whenever a record is inserted in the table, an event or stream can be picked up by a Lambda and do the necessary action.

CodePudding user response:

In short, no, not with the existing events you refer to - these are for monitoring the RDS service, not what you actually use it for, i.e. contents auditing (manipulation/tracking)

You can of course create notifications when an insert occurs, but you'll probably need to build/setup a few things.

A couple of ideas:

  1. Building something closer to the database logic, i.e. in your code base add something that fires a SQS / SNS event.
  2. If you can't (or don't want to) modify the logic that handle the database, maybe you could add a trigger that gets fired on INSERTs to the user table. Unfortunately I don't think there's support to execute a Lamdba from a trigger (as it is possible to do with PostgreSQL at the moment).
  3. Set up a database activity stream from RDS to Kinesis to monitor the INSERTS. This is a bit of a additional infrastructure to set up, so it might be a bit too much depending on your use case: "Database Activity Streams is an Amazon RDS feature that provides a near real-time stream of the activity in your Oracle DB instance. Amazon RDS pushes activities to an Amazon Kinesis data stream." From Kinesis, you can configure AWS Lambda to consume the stream and take action on INSERT events.

Some references:

https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis-example.html

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/DBActivityStreams.Enabling.html

  • Related