> AFAIK one has to `require` any modules inside...
# general
AFAIK one has to
any modules inside the callback.
This is no longer true actually (as of a couple releases ago).
How do I make instances reusable between requests then, e.g. a request with a static agent?
What do you have in mind here exactly? Code that only runs once per warm-up, not once per request?
Oh... I thought I got an error when tried to use
from the top of the file the other day. Yes, the code that runs once on warm-up, to reuse HTTP connections.
there are a couple of things that you can do here.
first, you can import the module like normal, then reference it inside your functions.
second, if you want to run warmup code, we have a mechanism ofr that as well, but i'd need to see your scenario/code to give advice on how to deal with this
basically, we have something we call a "factoryFunction" which runs once when the Lambda/Module loads and has time to set things up and then define the actual entrypoint function that will trigger each time the Lambda is hit.
The scenario is simple:
Copy code
// do once
const http = require("http");
const httpAgent = new http.Agent({ keepAlive: true });
// do at invoke
request({ url: url, pool: httpAgent }...
Ah, nice, I'll have a look at factories
right. perfect scenario for this
let me show an example
i'm also landing in a plane
so i may lose connection and be offline a while
this is no-arg function that, whne invoked, will produce the actual Lambda entry function.
you can see we pass that no-arg function to createFactoryFunction
which basically just passes hte isFactoryFunc bool down
seems clear
as you descend downwards into the lower level pulumi code, it understands how to properly generate this so you basically get:
module.exports = factoryFunc();
instead of
module.exports = func;