AWS Performance Notes
And finally, many Node.js client libraries, such as the Redis client, prevent the invocation from finishing, in which case, you need to set the callbackWaitsForEmptyEventLoop property in the invocation context object to false, just like this :
context.callbackWaitsForEmptyEventLoop = false // true by default.
// Times out due to typo
exports.function1 = (event, context, callback) => {
setInterval(() => console.log('Long wait'), 100000);
context.callbackWaitsForEmtpyEventLoop = false;
callback(null, 'Hello from Lambda');
};
PS – The serverless Aurora has some harsh limitations: MySql only, and a variant that doesn’t have support for a very current ANSI sql — no subqueries, no WITH, etc. Plus, the cold start time is horrible for web UI’s that are intermittently used. Tried to use it, but had to revert back to standard RDS instances.
// Require and initialize with default options const mysql = require('serverless-mysql')() // <-- initialize with function call
mysql.config({
host : process.env.ENDPOINT, database : process.env.DATABASE, user : process.env.USERNAME, password : process.env.PASSWORD})
await mysql.connect() // redundant since it is done automatically for you.
// Simple query let results = await query('SELECT * FROM table')
// Query with placeholder values let results = await query('SELECT * FROM table WHERE name = ?', ['serverless'])
// Perform connection management tasks await mysql.end() // Will terminate connection only if needed. // If connection usage is high, will terminate. mysql.quit() // Gracefully terminate the connection
// Get the underlying mysql connection object let connection = mysql.getClient()