5

我正在使用 nodejs 创建新的 lambda 函数。这个 lambda 函数在没有 aws-lambda 的情况下也能很好地工作。但是当我需要“aws-sdk”包时,它会发生错误并停止运行。错误是他们不能需要“aws-sdk”包。但是 aws-sdk 已经在 node_module 文件夹中。

我要你解决这个问题。非常感谢。

4

2 回答 2

12

这是一个非常有趣和奇怪的问题。

我也遇到过这个问题。起初,当我遇到这个问题时,我很担心,看起来真的很奇怪。我花了好几天的时间来解决这个问题。

原因真的很简单。由于 lambda 函数超时,您会遇到该问题。

默认超时为 3 秒,而 3 秒太短,无法加载 aws-sdk 包。

要加载 aws-sdk 包,它至少需要 6 秒。因此,我建议您在使用 aws-sdk 功能时将超时设置为 6 秒以上。

于 2018-01-15T19:23:46.323 回答
2

If this function runs thousands of times a day for 5 seconds or so then it can get quite costly. If your lambda is currently waiting around for another task to finish before completing execution then it would be better to consider a messaging system e.g. SNS.

I have a lambda function which requires aws-sdk, and then updates DynamoDB and upon the completion of that request invokes another lambda function and I've never seen all of these going above 1 seconds. If you are calling another lambda function make sure to include InvocationType: 'Event' so the original lambda completes right away instead of waiting around for the second lambda function to finish.

If that still doesn't work then it's time to try SNS as described here

于 2018-01-15T22:29:44.360 回答