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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With