Somashekar Muniyappa
Somashekar Muniyappa

Reputation: 483

How do we send notification to AWS SNS , for a record insert into Mysql Rds table?

I have a requirement where I need to send SNS notification based on data insert into Mysql RDs table?

Upvotes: 2

Views: 4649

Answers (3)

CodingOwl
CodingOwl

Reputation: 165

You can achieve this with RDS Trigger, Stored procedure.

Follow the steps below

  1. Create a stored procedure like below which points to your AWS Lambda function which can send the SNS.

DELIMITER $$ CREATE DEFINER=admin@% PROCEDURE procedure name(IN 'column name' 'column data type') BEGIN CALL > mysql.lambda_async('lambda ARN', > CONCAT('{ "val" : "', val, '"}')); END$$ DELIMITER ;

  1. Create a trigger which triggers the above procedure based on the scenario needed. In the given eg below, The stored procedure will be triggered when specified column value is equal or greater than 10

    DELIMITER $$ CREATE DEFINER=admin@% trigger 'trigger name' AFTER INSERT ON 'database.table' for each row begin IF (NEW.'column name',' ','')>=10 THEN CALL 'procedure name'(NEW.'column name'); END IF; END$$ DELIMITER ;

Make sure you have enough access to create a trigger and procedure. If not, grant the necessary access and try.

Upvotes: 3

E.J. Brennan
E.J. Brennan

Reputation: 46879

There is nothing built into mysql/rds that will do this for you. If this is a requirement I would suggest a custom layer that receives the insert request and does the insert and also sends the notification.

An API gateway request to a lambda function that does both tasks would probably work, but I wouldn't recommend it for a high velocity inputs (your writes to the db will be slowed).

For a low volume scenario it might work OK.

Upvotes: 2

gusto2
gusto2

Reputation: 12085

The "automatic" triggering is usually achieved by AWS Lambda or CloudWatch alerts. Lambda event sources are described here, however RDS is not among them.

I'd suggest the logic inserting data into RDS should send an SNS message

Upvotes: 3

Related Questions