serverless-mysql
serverless-mysql copied to clipboard
local function hangs
When I follow this example:
// Require and initialize outside of your main handler
const mysql = require('serverless-mysql')({
config: {
host : process.env.ENDPOINT,
database : process.env.DATABASE,
user : process.env.USERNAME,
password : process.env.PASSWORD
}
})
// Main handler function
exports.handler = async (event, context) => {
// Run your query
let results = await mysql.query('SELECT * FROM table')
// Run clean up function
await mysql.end()
// Return the results
return results
}
By invoking my function locally:
sls invoke local -f myFunction
results gets returned by the handler, but then it just hangs forever and the sls command never returns (command prompt doesn't come back). I need to hit ctrl c to end it.
I've tried setting:
context.callbackWaitsForEmptyEventLoop = false
And it still doesn't work, but I don't think that I should need to set that since I'm using an async function?
If I do mysql.quit() instead of end, my function doesn't hang, but obviously that's not great :)
From this link, it looks like maybe this is expected behavior:
https://github.com/serverless/serverless/issues/470#issuecomment-205372006
And maybe it should be covered in the documentation?
@srchulo did you get this all sorted out? I'm trying to get serverless-localstack working with serverless-mysql and I just can't get it to work. I believe that issue you reference provides some insight but I just can't develop with this plugin locally as it doesn't work unless just invoking functions (and even still, I'd have to change the code for staging/production).