5

I am creating new lambda functions using nodejs. And this lambda functions works well without aws-lambda. But when I require 'aws-sdk' package, it occurs the error and stop running. The error is that they can't require the 'aws-sdk' package. But aws-sdk was already in node_module folder.

I want you to solve this problem. Many thanks.

Derek Wang
  • 10,098
  • 4
  • 18
  • 39

2 Answers2

12

It's very interesting and strange question.

I have also experienced this issue too. At first, when I faced this problem, I was very worried and it looked really very strange. And it took me days and days of time to solve this problem.

The reason is really very simple. You meet that problem due to the timeout of lambda function.

The default timeout is 3 seconds and 3 seconds is too short time to load aws-sdk package.

To load aws-sdk package, it needs at least 6 seconds. So I recommend you to set the timeout more than 6 seconds whenever you want to use aws-sdk function.

Derek Wang
  • 10,098
  • 4
  • 18
  • 39
  • Thanks for your answer. Here you mentioned about timeout and where can I change the timeout? – Mikhail Zharnikov Jan 15 '18 at 19:24
  • 1
    When you visit amazon console on google chrome, visit lambda page. And click the lambda function you meet the error. In that function page, you can find timeout value in configuration section. Change that time and it will work. – Derek Wang Jan 15 '18 at 19:26
  • Cool! - was scratching my head from last hour. – Ravi Maniyar Nov 27 '19 at 08:31
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

Adi H
  • 668
  • 7
  • 9