我一直在做一些研究,但找不到关于在 Lambda 函数中使用 Knex JS 的好答案:
如何将 Knex 与 AWS Lambda 结合使用?第1875章
使用 Apex 和 AWS Lambda 的无服务器 URL 缩短器
在 AWS lambda 中使用 Promise.all()
这是我在 index.js 中的内容:
const knex = require('knex')({
client: 'pg',
connection: {...},
});
exports.handler = (event, context, callback) => {
console.log('event received: ', event);
console.log('knex connection: ', knex);
knex('goals')
.then((goals) => {
console.log('received goals: ', goals);
knex.client.destroy();
return callback(null, goals);
})
.catch((err) => {
console.log('error occurred: ', err);
knex.client.destroy();
return callback(err);
});
};
Run Code Online (Sandbox Code Playgroud)
我能够在本地连接和执行我的代码,但是当它部署到 AWS 时我遇到了一个有趣的错误——第一次调用总是成功,但之后的任何事情都失败了。我认为这与 …