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

Fail to start chromium on AWS with 1.0.0-57.2 #282

Open
HanXHX opened this issue Oct 25, 2020 · 5 comments
Open

Fail to start chromium on AWS with 1.0.0-57.2 #282

HanXHX opened this issue Oct 25, 2020 · 5 comments

Comments

@HanXHX
Copy link

HanXHX commented Oct 25, 2020

Hi,

I can't start chromium on AWS Lambda. It seems, the shipped chromium version is not statically compiled with libnss3.so.

Used code:

const launchChrome = require('@serverless-chrome/lambda');
const request = require('superagent');

module.exports.getChrome = async () => {
    const chrome = await launchChrome({
        flags: ['--no-sandbox', '--headless']
    });

    const response = await request
        .get(`${chrome.url}/json/version`)
        .set('Content-Type', 'application/json');

    const endpoint = response.body.webSocketDebuggerUrl;

    return {
        endpoint,
        instance: chrome,
    };
};

Logs under AWS:

INFO	@serverless-chrome/lambda: Spawning headless shell
INFO	@serverless-chrome/lambda: ChromeLauncher No debugging port found on port 9222, launching a new Chrome.
INFO	@serverless-chrome/lambda: Launcher Chrome running with pid 25 on port 9222.
INFO	@serverless-chrome/lambda: Waiting for Chrome 0
INFO	@serverless-chrome/lambda: Waiting for Chrome 1
...
INFO	@serverless-chrome/lambda: Waiting for Chrome 10
INFO	@serverless-chrome/lambda: Error trying to spawn chrome: Error: connect ECONNREFUSED 127.0.0.1:9222
INFO	@serverless-chrome/lambda: stderr log: /var/task/node_modules/@serverless-chrome/lambda/dist/headless-chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

Environement:

  • NodeJS 12
  • @serverless-chrome/lambda: 1.0.0-57.2

Best,

EM

@mikkopori
Copy link

Hello,

while trying to make chromium run on aws I found this:
https://aws.amazon.com/blogs/compute/upcoming-changes-to-the-python-sdk-in-aws-lambda/

to solve the above problem. Not fully succesfull yet, but I thought I would post it anyway if it helps anyone.

Br,

Mikko

@bdombro
Copy link

bdombro commented Mar 5, 2021

Did y'all figure this out?

@fprochazka
Copy link

I've solved it by using a custom docker image for lambda 🤷

@ariel-frischer
Copy link

@fprochazka How exactly? Did you use this package?

@fprochazka
Copy link

You can find all the required info here: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-image.html

my Dockerfile is derived from the AWS documentation:

ARG BUILD_IMAGE_BASE
FROM ${BUILD_IMAGE_BASE} as builder

RUN set -ex \
 && yarn install --non-interactive --frozen-lockfile --no-progress \
 && yarn run package

FROM docker.cogvio.dev/cogvio/dev/node-js:12-alpine

RUN set -ex \
 && apk --no-cache upgrade \
 && apk add --no-cache --update chromium unzip nss curl

ENV LAMBDA_TASK_ROOT=/var/task
ENV LAMBDA_RUNTIME_DIR=/var/runtime
ENV PATH="${LAMBDA_TASK_ROOT}/node_modules/.bin:${PATH}"

WORKDIR ${LAMBDA_TASK_ROOT}

# override global config to ensure local repository is at predictable path
ENV YARN_CACHE_FOLDER=/var/cache/yarn
RUN mkdir -p $YARN_CACHE_FOLDER

COPY --from=builder /srv/.serverless/pdf.zip ${LAMBDA_TASK_ROOT}
RUN set -ex \
 && unzip -q pdf.zip \
 && rm -f pdf.zip \
 && du -sh ${LAMBDA_TASK_ROOT} \
 && chmod -R 0777 /tmp

ENTRYPOINT ["/usr/local/bin/npx", "/var/task/node_modules/aws-lambda-ric/bin/index.js"]
CMD [ "src/handlers/pdf.default" ]

The builder step just builds the nodejs app, nothing special there. And as you can see, I'm then installing chromium directly from alpine repositories, as I was able to test locally, that it works in headless correctly.

In the app itself, I'm still using serverless, but I've removed the dependency on this package, as it's not needed anymore and I can just start the chromium in headless directly and can get rid of a bunch of the workarounds for Amazon Linux. But it was a pain in the butt to get it working smoothly, not gonna lie.

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

5 participants