Problems when setting up jsreport in lambda.



  • Hi there.
    I'm trying to set up the jsreport on lambda. I'm using the tutorial from https://jsreport.net/learn/aws-lambda-serverless, and the only change is an extra package for the s3 storage:
    @jsreport/jsreport-fs-store-aws-s3-persistence.

    The problem is that the whole layer package exceeds the AWS limit:

    0_1726089171091_upload-7c44016b-3703-4a24-8ffb-7b82654535e5

    I would appreciate any suggestion on how I can fix that.

    Thank you



  • Yes, the layer with all jsreport modules is on the edge of the size. Maybe you can try to create one layer general, and one layer with additional deps. Not sure now if that works, but something to explore...

    However, why do you need that extension? If you have templates in s3, you can also download them in runtime to local tmp files and use the plain fs store. Somewhere here
    https://github.com/jsreport/jsreport-aws-lambda-starter-kit/blob/master/index.js#L34



  • I've actually started exploring that option with multiple layers.

    As for the use case - I'm storing my templates on s3 and I'm running jsreport with studio locally to manage my templates. I want lambda function to point at the same location on s3.



  • Unfortunately the multiple layers option didn't work:
    0_1726090979185_upload-f06f43d4-ea46-4fb9-9ba7-d0b955016ecd

    I was looking into building the docker image for lambda, but I didn't find any info. Is it possible?



  • I see, the size limit is apparently calculated with all layers.

    The problem is that the aws-sdk, which is used in s3 persistence extension, has 80 MB. I was able to fit to the size limit when removing aws-sdk files that aren't used.

    This is the glob what to remove

    node_modules/**/aws-sdk/apis/!(metadata.json|s3-2006-03-01.min.json|s3-2006-03-01.paginators.json|s3-2006-03-01.waiters2.json|sts-2011-06-15.min.json|sts-2011-06-15.paginators.json),
    node_modules/**/aws-sdk/clients/*.ts,
    node_modules/**/aws-sdk/clients/!(s3.js|sqs.js|cognitoidentity.js|sts.js),
    node_modules/**/aws-sdk/dist,
    node_modules/**/aws-sdk/dist-tools,

    You can place the code here
    https://github.com/jsreport/jsreport-aws-lambda-starter-kit/blob/master/createLambdaLayer.js#L67



  • Thank you for looking into that. I will give it a go later Today and report back.



  • That seems to do the trick. I've managed to upload layer and add it to the function. I've tested it in AWS console with hello world example and it works, just need to test it with my templates on s3. Thanks



  • We are using a Docx template to generate the reports on AWS Lambda. Is there a way to export the same in pdf, html or xls without having to rely on other external libraries



  • Hi Jan.

    I'm happy to report that this is working as expected now. Lambda can access templates on s3 and renders pdf without problems.

    Thank you!


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.