Pdfkit s31/16/2024 Ensure you've installed the CLI and have configured an IAM User with an Access Key in your AWS Profile. Initially, a new Pulumi project will be initialized using the Pulumi CLI. Therefore, this implementation will be using Pulumi. It directly deploys infrastructure using the typed language, rather than transpiling back to CloudFormation, which makes your deployments a bit faster. Pulumi is an IaC tool that enables developers to provision infrastructure using their favourable programming language. We will be using the IaC approach with Pulumi. There are several ways this infrastructure can be provisioned. The SQS Queue will push the failed messages to a DLQ if the Lambda processing a message fails a defined number of times. DLQ - A Dead Letter Queue to handle error messages.SES - To email the signed URL to the client.An S3 Storage Bucket - To store the generated PDF. It allows the implementation of the Queue-Based Load Levelling Design Pattern. This helps decouple the AWS Lambda function that generates the PDF, allowing the function to independently scale and not run out of possible concurrency limits. An SQS Queue - The API Gateway will be integrated with a Lambda function that pushes data to an SQS Queue.An API Gateway - For clients to request a PDF.The architectural diagram shown above utilizes the AWS Serverless ecosystem to build a PDF generation service. Therefore, let us take a look at the serverless architecture for the solution that we will be building for the PDF service. This ensures that a client can obtain a copy of the PDF in a highly secure manner.Īdditionally, serverless computing helps you design and develop solutions that are highly available, resilient and cost-efficient.Ī Resilient, Scalable PDF Generation Architecture for Serverless The recommended approach for PDF generation is to use the server side. The Best Way Out - Server-Side Generation It does not scale: If your user is using a low-end device (or even Internet Explorer), your libraries may not be able to generate the PDF efficiently.ĭesigning PDFs using the client-side approach is suitable for large-scale, demanding applications due to the discussed negatives. However, if you choose to sign your document on the client side, you will be putting your keys at risk of exposure. There is no security: You cannot sign a document on the client side without exposing your private key. There is no traceability: You aren’t able to keep track of the location and the device that was used to create the PDF. A user can easily tamper with the HTML content beforehand and compile the PDF in the client application before sending it to the backend. There is no authenticity: Since the PDF is being generated on the client side, the software product has no say in what gets compiled in the PDF. Though it creates a fast and efficient process, it does have its set of negatives. For example, if you’re using React, you might have used compile a PDF and download it directly in the web browser. When tasked with PDF generation, a go-to option would be to generate the PDF on the client side with the available data. Therefore, as a serverless developer, it’s important to ensure that you can design scalable and resilient PDF generation solutions for applications. Likewise, there will come a time when you need to implement a PDF generator on your application as well. For example, SignRequest uses PDFs to email a copy of a signed PDF document when all participants sign it. For example, an application may utilize PDFs to send an email of an invoice for payment confirmation, a report or even a custom-typed document. To make my life easier I'm using a serverless package to handle deployment to AWS Lambda and chrome-aws-lambda to help out the deployment of puppeteer to AWS Lambda.Using AWS Lambda, Amazon SQS, Amazon API Gateway, Amazon S3, AWS Lambda Layers and Pulumi to Build a Scalable PDF Generation ServiceĪlmost all modern web applications use PDFs. It's a bit overkill for the current use case but at the same time, it is more future proof due to html+css base structure. I ended up choosing Puppeteer for this project. With NodeJS I had already done a small project with database connection so I knew that it would work.įor NodeJS I still needed a package to generator PDF, and I found following options: Originally I was planning to use Python and a Reportlab for this project but a connection to PostgreSQL database ended up being too complex to configure. Luckily both Google (Functions) and AWS (Lambda) have an event-driven service which is only running on request. Since these PDFs are not generated too often, it doesn't make sense to 24/7 running service. Recently I have needed to solve a problem that involves generating a PDF file based on database content. Generate a PDF in AWS Lambda with NodeJS and Puppeteer
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |