I have NodeJS 12.x Lambda like this, and I'm using middy.js to connect to a RedShift cluster, here is an excerpt:
const middy = require('@middy/core')
const dbManager = require('@middy/db-manager');
const lambda = middy(async (event, context) => {
const { db } = context;
const records = await db.distinct('XXX').from('YYY');
// print result
console.log(records);
// return result
return {
'statusCode': 200,
'body': JSON.stringify(records)
}
});
lambda
.use(dbManager({
config: {
client: 'pg',
connection: {
host: 'XXX',
port: '1111',
schema: 'public',
user: 'XXX',
password: 'XXX',
database: 'XXX'
}
}
}));
module.exports = { lambda }
When I run this Lambda the result are retrieved (i.e. console.log
print out the results) but the function remains pending until it doesn't reach its timeout. I'm pretty sure I'm missing something with async/await mechanism but I don't know what and where I have to change.