Skip to content

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

@kaldebert

Description

@kaldebert

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://raw.githubusercontent.com/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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions