Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using require in AWS lambda functions

I am currently researching AWS lambda functions and I can't find anywhere if I can use the require statement in them so that I can use other, non-lambda functions. I know about zipping the node modules folder but this doesn't help me here as I don't intend to use a node module, thanks for any answers!

like image 793
Rohan Hadnum Avatar asked Jan 19 '17 19:01

Rohan Hadnum


People also ask

Does Lambda require load balancer?

You can use a Lambda function to process requests from an Application Load Balancer. Elastic Load Balancing supports Lambda functions as a target for an Application Load Balancer. Use load balancer rules to route HTTP requests to a function, based on path or header values.

Is requests available in Lambda?

The Lambda runtimes for Python 3.8 and later do not include the 'requests' module. Customers using 'requests' with these runtimes should package the 'requests' module with their function code or as a Lambda layer. Update (November 11, 2021):

When you should not use AWS Lambda?

You do not want to use Lambda for long-running workloads because it runs instances/functions for up to 15 minutes at a time. It limits concurrent function executions to 1,000. AWS Lambda bills can quickly run through your budget if you are unsure how to optimize AWS costs.


2 Answers

Just to add to Justin's answer, yes you can require other files in lambda with this structure as an example:

| main.js << The handler is here
| func1.js
| func2.js

and in the main file:

// main.js
require('./func1.js');
require('./func2.js');
like image 163
Naguib Ihab Avatar answered Oct 10 '22 04:10

Naguib Ihab


Yes, you can. You just have to ensure that the node_modules folder is uploaded as part of your package (you won't be able to use the console editor). You can read more details on the AWS Blog:

Using Packages and Native nodejs Modules in AWS Lambda

like image 33
Justin Niessner Avatar answered Oct 10 '22 05:10

Justin Niessner