'How to install Ghostscript in aws Lambda?

Error Message: Please make sure that Ghostscript is installed", "errorType": "RuntimeError"

import camelot

def pdfToJson(event=None, context=None): 
    tables = camelot.read_pdf("./week-1-2019-20.pdf")  
    tables[0].df.to_json("./sample.json")
  1. Installed the dependencies with pip install -t .
  2. But still getting the error.

How can I install the "ghostscript" dependency in my python code?



Solution 1:[1]

I haven't tried this myself, but you should be able to do this with a Lambda Layer. You can see an example of how this is done via https://github.com/BearTail/ghostscript-aws-lambda-layer.

Some magic may also be needed to tell camelot that the Ghostscript binary can be found at /opt/bin/gs, as that isn't a normal location for it.

Solution 2:[2]

In camelot library communication with Ghostscript done via a low-level C-API interface with ctypes usage. Ghostscript is used to generate images from pdf being processed by the library.

You do not need to install any python binding by yourself, the only requirement is Ghostscript itself. The easiest way to install is to use repositories/CD, on Ubuntu simple as that:

sudo apt-get install -y ghostscript
gs --version

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SamStephens
Solution 2 funnydman