AWS Lambda serverless

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.

Get started

Clone starter kit repo

We prepared starter github repository jsreport-aws-lambda-starter-kit for you. The first you need to clone it.

git clone

Prepare templates

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.

Prepare layer

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 to a s3 bucket. Then create AWS lambda layer referencing the uploaded zip with nodejs 20.x runtime.

lambda layer

Create lambda function

Then create lambda function with node 20.x runtime.

lambda function

You can disable the default automatic lambda runtime updates to avoid unexpected break of OS-chrome dependencies.

Upload lambda package

The next step is preparing the lambda package. This can be done using the following script.

node createLambdaPackage.js

Then upload the prepared through the AWS Console.

lambda upload

Add layer to the function

Then add the layer you previously created.

lambda add layer

lambda add layer2

Increase memory and timeout

The default 3s timeout and 128mb memory isn't sufficient for bigger reports. We recommend increasing timeout to 60s and memory to 1024mb.

lambda change configuration

Test the function

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.

lambda test

You can also use script test.js from the starter kit to test function remotely using AWS node.js SDK.

  1. Create AWS IAM user with AWSLambdaRolerole
  2. Set environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
  3. Edit test.js and set your AWS region and the lambda name
  4. Run node test.js
  5. Check the report.pdf was properly rendered

jsreport version