You'll want to have lib_mysqludf_sys (this link is to a branch of a fork that includes a fix for x64 systems) installed on your MySQL Server for this to work.
Last active
January 1, 2020 20:56
-
-
Save Spetnik/e442f4cf2a3b0cad7f1089b1cc602154 to your computer and use it in GitHub Desktop.
Execute Lambda using mysql.lambda_async from local MySQL server using UDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER $$ | |
USE `mysql` $$ | |
CREATE PROCEDURE `lambda_async`( | |
lambda_function_ARN VARCHAR(1024), | |
lambda_function_input TEXT | |
) | |
BEGIN | |
DECLARE v_null INT; | |
SET v_null := sys_exec(CONCAT('/usr/bin/node /usr/local/runlambda/runlambda ', lambda_function_ARN, ' ', lambda_function_input)); | |
END $$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Saved at /usr/local/runlambda/runlambda.js | |
const AWS = require('aws-sdk'); | |
AWS.config = new AWS.Config({ | |
accessKeyId: 'XXXXXXXXXXXXXXXXXXXX', | |
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | |
region: 'us-east-1' | |
}); | |
const funcName = process.argv[2]; | |
const payload = process.argv[3] || '{}'; | |
const lambda = new AWS.Lambda(); | |
lambda.invoke({ | |
FunctionName: funcName, | |
Payload: payload, | |
InvocationType: 'Event' | |
}, (err, data)=>{ | |
if(err){ | |
console.error(err, err.stack); | |
return; | |
} | |
}); |
This is for a local MySQL installation to emulate the lambda_async function available in Aurora.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this work with Aurora serverless?