I am trying to add a trigger to a table on Amazon Aurora but when I run the following CREATE TRIGGER
command nothing happens:
delimiter $$
CREATE TRIGGER trigger_lambda_function_on_special_row_update
AFTER UPDATE ON example_table
FOR EACH ROW
BEGIN
IF NEW.special_id = 12345 THEN
CALL mysql.lambda_async("arn:aws:lambda:[region]:[account]:function:myfunction", CONCAT('{"param":"', NEW.id, '"}'));
END IF;
END;$$
delimiter ;
By "nothing happens", I mean that when I run CREATE TRIGGER
the database is still responsive — I can Ctrl+C to interrupt the query — but the query just sits there doing nothing until I finally get the response MySQL has gone away
.
Taking the mysql.lambda_async
out of the trigger and running it is fine. I can see the invocation on AWS Lambda so I know this part is working.
I did a bit of reading about triggers on Aurora and I can see some people mentioning the need to enable log_bin_trust_function_creators
in the AWS Console "Parameter Groups" options if you want to use triggers, but this is only available for the mysql5.5+ parameter group family. If you want to invoke functions on Lambda, the option for this is only available in the aurora5.6 parameter family group. It would seem that you can't do both.
HOWEVER! You must be able to do both; there are plenty of examples out there, even from Amazon themselves, where this seems entirely possible:
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.Lambda.html (See: Example: Invoke an AWS Lambda Function to Publish an Event from a Trigger)
So I'm confused. Has anybody else made this process work?
I've solved my own question: When you run
CREATE TRIGGER
, although Aurora appears to hang it has actually created the trigger but it is not giving confirmation of the action finishing. As such, there is no problem. Just check your database triggers after running theCREATE TRIGGER
command to see if it worked and don't rely on Aurora to tell you.