Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

AWS Lambda + PDFtk Example

This repository provides a working example of using PDFtk within AWS Lambda. AWS Lambda runs on Amazon Linux, which does not officially support PDFtk or GCJ, one of PDFtk's dependencies. This example works by including both a PDFtk binary and the libgcj shared library.

Run the Example

To run the example, first package up the project into a ZIP file by running:


Then, simply upload this ZIP to AWS Lambda. When testing with the Lambda web interface, you should see the function succeed and output PDFtk's version and copyright information.

You can very easily expand on this boilerplate and use PDFtk in the way it was intended for - manipulating PDF files.

How it Works

AWS Lambda supports binary dependencies by allowing them to be included in uploaded ZIP files. However, because Amazon Linux does not support PDFtk or GCJ, PDFtk was built from source in CentOS, a close relative of Amazon Linux. I spun up a CentOS 6 machine in EC2 and followed the instructions on the PDFtk website to build PDFtk from source.

sudo yum install gcc gcc-java libgcj libgcj-devel gcc-c++



cd pdftk-2.02-dist/pdftk

make -f Makefile.Redhat

sudo make -f Makefile.Redhat install

Then I copied the resulting pdftk binary and /usr/lib64/ shared library into the bin/ directory of my Lambda project.

The entry point to the lambda function, index.js, alters the PATH and LD_LIBRARY_PATH environment variables to let the system know where to find the binary and the GCJ dependency.

Using PDFtk in Amazon Linux

It should be possible to use the PDFtk binary and GCJ shared library located in the bin/ directory of this file to run PDFtk in Amazon Linux on EC2. Simply copy them onto the machine and put them in the correct path, or call them directly:

LD_LIBRARY_PATH=/path/to/ /path/to/pdftk --version


Example project that runs PDFtk in AWS Lambda



No releases published
You can’t perform that action at this time.