Asynchronous Initialization Extension Layer for NodeJs
chuckbarkertech opened this issue · 0 comments
Asynchronous Initialization Extension Layer for NodeJs
The Problem
Asynchronous operations do not complete during the initialization phase. This is specifically a problem for provisioned concurrency. One of the major benefits is that long running operations can be initialized during provisioned concurrency, but this does not happen with AWS Lambda NodeJs operations.
A JavaScript IIFE can be used to start a promise during the initialization phase, but it does not complete until the function is actually called. Sometimes it does not complete until multiple requests later since it is running as a background task in the event loop.
The Solution
An AWS Extension layer can be used to keep the AWS Lambda container active until the AWS Lambda NodeJs function initialization completes all of its asynchronous operations. I have linked an example repository where I demonstrate this.
I would like to turn this over to the aws-lambda-extensions repository. Is it Ok to create a pull request for this? Are there any questions or modifications needed?
The example is here: https://github.com/chuckbarkertech/nodejs-example-async-init-extension