Reputation: 483
I have a requirement where I need to send SNS notification based on data insert into Mysql RDs table?
Upvotes: 2
Views: 4649
Reputation: 165
You can achieve this with RDS Trigger, Stored procedure.
Follow the steps below
DELIMITER $$ CREATE DEFINER=
admin
@%
PROCEDUREprocedure name
(IN 'column name' 'column data type') BEGIN CALL > mysql.lambda_async('lambda ARN', > CONCAT('{ "val" : "', val, '"}')); END$$ DELIMITER ;
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
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