You can run jsreport serverless in AWS Lambda. This is the very convenient way to run cheap and automatically scalable reports rendering without a need for paying for the actual servers.
This documentation helps you with creating the AWS Lambda running jsreport, deploying templates and remote invocation of the rendering.
We prepared starter github repository jsreport-aws-lambda-starter-kit for you. The first you need to clone it.
git clone https://github.com/jsreport/jsreport-aws-lambda-starter-kit.git
Install dependencies and start jsreport...
npm i
npm start
On Linux, make sure you have the required chrome shared libraries mentioned in the install docs.
Then open http://localhost:5488
and prepare jsreport templates the same way you would do when running normal jsreport.
The best way is to create lambda layer with node_modules folder and then have just templates and configs inside the lambda function package itself. There is createLambdaLayer.js
script that helps you with that.
Call it using
node createLambdaLayer.js
Then log in to AWS console and upload the prepared layer.zip
to a s3 bucket.
Then create AWS lambda layer referencing the uploaded zip with nodejs 20.x runtime.
Then create lambda function with node 20.x runtime.
You can disable the default automatic lambda runtime updates to avoid unexpected break of OS-chrome dependencies.
The next step is preparing the lambda package. This can be done using the following script.
node createLambdaPackage.js
Then upload the prepared lambda.zip
through the AWS Console.
Then add the layer you previously created.
The default 3s timeout and 128mb memory isn't sufficient for bigger reports. We recommend increasing timeout to 60s and memory to 1024mb.
The AWS Console includes convenient way to test the function directly on the web. The function expects standard jsreport rendering request as the parameter and outputs base64 encoded report output.
You can also use script test.js
from the starter kit to test function remotely using AWS node.js SDK.
node test.js
report.pdf
was properly rendered