An easy to deploy implementation of the html-pdf package for AWS Lambda
You need to create a PDF from a HTML string, save the generated PDF file to AWS S3 and return the URL of the file so you can download it or do whatever you need with it. All of this using an AWS Lambda function.
- Clone this repo.
- Run
npm install
to get all the package dependencies. - (Optional) Go to
./node_modules/phantomjs-prebuilt/lib/phantom/bin/
and delete the binary file generated by your OS (you won't need this as you'll use a Linux generated binary). This will reduce the size of your zip file. - Remember to change the name of your S3 bucket on the
S3config
variable - Zip everything and upload that to your AWS Lambda function.
This repo was built from different sources and these links could help you.
- @marcbachmann npm package for HTML to PDF generation using PhantomJS
- Marc Delagrammatikas' article, "Creating PDFs from HTML with AWS Lambda and API Gateway"
- santiagobasulto shed some light to use a different binary
- Got the correct binary file for AWS Lambda from this repo, thanks @TylerPachal!
Feel free to fork this repo and contribute
- Return CORS headers for Amazon API Gateway
- Convert AWS S3 HTML files to PDF
- Convert any given URL to PDF