All Projects → ARautio → aws-lambda-pdf-generator-puppeteer

ARautio / aws-lambda-pdf-generator-puppeteer

Licence: MIT License
PDF generator for AWS lambda with puppeteer

Programming Languages

javascript
184084 projects - #8 most used programming language
Pug
443 projects

Projects that are alternatives of or similar to aws-lambda-pdf-generator-puppeteer

Asciidoctor Web Pdf
Convert AsciiDoc documents to PDF using web technologies
Stars: ✭ 219 (+321.15%)
Mutual labels:  pdf-generation, puppeteer
Screenshoteer
Make website screenshots and mobile emulations from the command line.
Stars: ✭ 1,650 (+3073.08%)
Mutual labels:  pdf-generation, puppeteer
Tea School
Simplified HTML + CSS --> PDF Generator for Nodejs
Stars: ✭ 326 (+526.92%)
Mutual labels:  pdf-generation, puppeteer
Serverless Puppeteer Layers
Serverless Framework + AWS Lambda Layers + Puppeteer = ❤️
Stars: ✭ 247 (+375%)
Mutual labels:  aws-lambda, puppeteer
Aws Lambda Libreoffice
85 MB LibreOffice to fit inside AWS Lambda compressed with Brotli
Stars: ✭ 145 (+178.85%)
Mutual labels:  aws-lambda, pdf-generation
Chromda
λ 🖼️ Chromda is an AWS Lambda function for capturing screenshots of websites.
Stars: ✭ 481 (+825%)
Mutual labels:  aws-lambda, puppeteer
Md To Pdf
Hackable CLI tool for converting Markdown files to PDF using Node.js and headless Chrome.
Stars: ✭ 374 (+619.23%)
Mutual labels:  pdf-generation, puppeteer
Puppeteer Lambda Starter Kit
Starter Kit for running Headless-Chrome by Puppeteer on AWS Lambda.
Stars: ✭ 563 (+982.69%)
Mutual labels:  aws-lambda, puppeteer
Chrome Aws Lambda
Chromium Binary for AWS Lambda and Google Cloud Functions
Stars: ✭ 2,502 (+4711.54%)
Mutual labels:  aws-lambda, puppeteer
Dhalang
Generate PDFs and make screenshots of HTML using Puppeteer in Ruby
Stars: ✭ 41 (-21.15%)
Mutual labels:  pdf-generation, puppeteer
mangum-cli
CLI tools for use with Mangum
Stars: ✭ 14 (-73.08%)
Mutual labels:  aws-lambda
cfn-api-gateway-custom-domain
API Gateway custom domains as CloudFormation resources, backed by Let's Encrypt
Stars: ✭ 17 (-67.31%)
Mutual labels:  aws-lambda
SlackWebhooksGithubCrawler
Search for Slack Webhooks token publicly exposed on Github
Stars: ✭ 21 (-59.62%)
Mutual labels:  puppeteer
mysql2-lambda
Precompiled Mysql2 Gem for AWS Lambda
Stars: ✭ 19 (-63.46%)
Mutual labels:  aws-lambda
jschr.io
The static website generator service behind jschr.io.
Stars: ✭ 70 (+34.62%)
Mutual labels:  aws-lambda
vrt-react
Take a screenshot 📸 of React component. Push it and compare images in pull request.
Stars: ✭ 19 (-63.46%)
Mutual labels:  puppeteer
Hodor
Hodor is a an automation application that is used to open the door controlled by an intercom system from Slack using a custom slash command.
Stars: ✭ 21 (-59.62%)
Mutual labels:  aws-lambda
lambda-checklist
The checklist for meticulous serverless engineers
Stars: ✭ 26 (-50%)
Mutual labels:  aws-lambda
hyper-kube-config
H Y P E R K U B E - A Serverless API and kubectl plugin providing a storage and retrieval Kubernetes cluster credentials. Hyperkube leverages AWS Secrets Manager for storing credential information.
Stars: ✭ 27 (-48.08%)
Mutual labels:  aws-lambda
next-serverless
☁️ next-serverless deploys your next.js application to AWS Lambda with minimal or even no configuration.
Stars: ✭ 80 (+53.85%)
Mutual labels:  aws-lambda

AWS lambda PDF generator example

The purpose of this repository is to demonstrate a PDF generator inside AWS lambda with chrome-aws-lambda, serverless, pug and knex. This has been done as part of the article in dev.to

Setup

  1. Initialize serverless either inside project or globally (after installing package globally) with
serverless
  1. Modify PUG template inside src/
  2. Fetch data for the template. In this repository we use knex and postgresSQL. For production use I would suggest to add database username and password to environmental variables either inside deployment platform or in AWS.
  3. Deploy with
npm run deploy:dev

Usage

Deploying this to AWS will generate you an url like https://xxxx.execute-api.*area*.amazonaws.com/development/pdf/{yearMonth} in development and https://xxxx.execute-api.*area*.amazonaws.com/production/pdf/{yearMonth} in production.

When running this setup with 1024 MB memory, it takes rougly 4 seconds to execute. With more complex pages or data fetching default timeout may not be enough so you may need to increase the timeout either with serverless.yaml or straight from AWS console.

Puppeteer is pretty versatile so you can create PDF from your own html file like in this example with PUG template language or calling URL.

More information regarding this repository can found from Generate a PDF in AWS Lambda with NodeJS and Puppeteer dev.to post.

Security

Since this deployment setup exposes your PDF generator straight to open the internet, it can be called just by knowing the URL. This can lead to the abuse of your application resulting in either your data to leak or getting a huge bill from AWS.

To mitigate the risk, there are several ways to increase security and reduce/block the abuse:

  1. Enabling the API key to API Gateway to limit access and monitor the usage. In this option, a client needs to send an API key in the request to be able to use the lambda function so you need to create a way to get the API key to the client. It won't fully block the abuse since the API key is exposed when making the request and the same key can be used again but it will give you a chance to limit the usage amount. This works pretty well when you don't have authorization in your application.

Serverless has API key plugin to create this for your lambda function.

  1. Enable authorizer to API Gateway (either AWS_IAM or custom). In this option, you need to have a user authorization set up (either provided by AWS or using a custom one). This method blocks the abuse from unauthorized use but if you have open registration, the user can still make an unlimited amount of request.

  2. Checking authorization before starting up puppeteer. This is almost the same as the previous option but the authorization check is done inside the lambda and not in the API gateway. The difference is that you don't have to have a custom authorization function the Lambda function handles itself. It won't block the abuse since the endpoint will respond every time but it makes execution time for unauthorized use a lot smaller.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].