当使用aws-sdk NodeJS包编写一个Lambda函数用于Shopify webhook时,我注意到包的require语句需要超过3秒才能加载。这会导致问题,因为Shopify需要在5秒内响应其webhook。我从我的函数中抽象出代码来自行测试并得到相同的结果:
exports.handler = (event, context, callback) => {
const start = new Date().getTime();
console.log('start: '+ new Date())
require('aws-sdk');
console.log('end:' + new Date())
const end = new Date().getTime();
console.log('length: ' + (end - start) + 'ms');
callback();
}
以下是输出:
START RequestId: Version: $LATEST
2017-11-30T13:23:57.506Z start: Thu Nov 30 2017 13:23:57 GMT+0000 (UTC)
END RequestId:
REPORT RequestId: Duration: 3001.29 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 31 MB
2017-11-30T13:24:00.499Z Task timed out after 3.00 seconds
答案 0 :(得分:1)
问题似乎是我没有给Lambda函数足够的内存来加载包。我通过以下结果增加了内存: