Skip to content

Instantly share code, notes, and snippets.

@Spetnik
Last active January 1, 2020 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spetnik/e442f4cf2a3b0cad7f1089b1cc602154 to your computer and use it in GitHub Desktop.
Save Spetnik/e442f4cf2a3b0cad7f1089b1cc602154 to your computer and use it in GitHub Desktop.
Execute Lambda using mysql.lambda_async from local MySQL server using UDF

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.

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 $$
// 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;
}
});
@Ricardo1980
Copy link

Does this work with Aurora serverless?

@Spetnik
Copy link
Author

Spetnik commented Jan 1, 2020

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