Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find the libgs file during runtime in serverless environment (AWS Lambda) #65

Open
kaldebert opened this issue Jun 16, 2021 · 1 comment

Comments

@kaldebert
Copy link

Is it possible to use ghostscript4js and ghostscript in a serverless environment as AWS Lambda (and Layers)?

I tried to install both ghostscript4js and ghostscript from a Dockerfile to be uploaded in a AWS Layer (Lambda).

FROM lambci/lambda-base-2:build

# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

ENV GS_TAG=gs952
ENV GS_VERSION=9.52
ENV NVM_VERSION=0.38.0
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 12.13.0

RUN yum install -y wget

# Install Ghostscript
RUN mkdir /usr/local/src/ghostscript && \
  cd /usr/local/src/ghostscript && \
  wget -qO - https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/$GS_TAG/ghostscript-$GS_VERSION.tar.gz | tar -zxf - && \
  cd ghostscript-$GS_VERSION && \
  ./configure --without-luratech && \
  make so

# Copy Ghostscript to be used by Ghostscript4JS
RUN mkdir -p /opt/ghostscript/bin
RUN mv /usr/local/src/ghostscript/ghostscript-$GS_VERSION/sobin/* /opt/ghostscript/bin

# Install nvm
RUN mkdir /usr/local/nvm && \
  wget -qO- https://github.com/raw/nvm-sh/nvm/v$NVM_VERSION/install.sh | bash

# Install node and npm
RUN source $NVM_DIR/nvm.sh && \
  nvm install $NODE_VERSION && \
  nvm alias default $NODE_VERSION && \
  nvm use default

ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

# Install Ghostscript4JS
RUN mkdir /opt/nodejs && \
  cd /opt/nodejs && \
  npm init -y && \
  npm install node-gyp && \
  npm install ghostscript4js --GS4JS_HOME="/opt/ghostscript/bin"

# Create the ZIP file
RUN cd /opt && zip -r /tmp/gs.zip ghostscript nodejs

But when the AWS Lambda is called, I got this error:

Error: libgs.so.9: cannot open shared object file: No such file or directory
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1057:18)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at bindings (/opt/nodejs/node_modules/bindings/bindings.js:112:48)
    at Object.<anonymous> (/opt/nodejs/node_modules/ghostscript4js/lib/ghostscript4js.js:25:31)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)

Where should be the libgs file during the runtime?
In the GS4JS_HOME folder or is it copied in another folder during ghostscript4js'installation?

@kaldebert kaldebert changed the title Cannot f Cannot find the libgs file during runtime in serverless environment (AWS Lambda) Jun 16, 2021
@NickNaso
Copy link
Owner

Hi @kaldebert,
it search the library libgs.so in the folder you set using the evn variable GS4JS_HOME. When the module is loaded it needs to load the shared library libgs.so otherwise you get the error you reported, An idea could be to copy the library in the folder of your project and the try to install it.
Es.
The folder for your project is my-project and you copy the content of the folder /usr/local/src/ghostscript/ghostscript-$GS_VERSION/sobin/* to my-project/gs
The you can install using the following command:
npm install ghostscript4js --GS4JS_HOME=../../../gs
I hope that this help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants