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

chrome-aws-lambda changes (node10.x support) #15

Open
devasur opened this issue Oct 20, 2019 · 6 comments
Open

chrome-aws-lambda changes (node10.x support) #15

devasur opened this issue Oct 20, 2019 · 6 comments

Comments

@devasur
Copy link
Contributor

devasur commented Oct 20, 2019

AWS is removing the Node 8.10 support. In connection with this @alixaxel has updated the https://github.com/alixaxel/chrome-aws-lambda to support Node 10. He is packaging a few required dependencies in the /bin folder. Also the naming convention for chromium build has changed. As you can see the download script needs corresponding fixes.

alixaxel/chrome-aws-lambda#37

One pickle with here is that @alixaxel's fix is not working nice with puppeteer-core. It needs a specific instantiation through its library for puppeteer.

This in all is currently braking your example with Node 10. Giving you a heads up. I will also try to find a working model and if I do will do a PR. Might be faster for you.

@alixaxel
Copy link

@devasur

One pickle with here is that @alixaxel's fix is not working nice with puppeteer-core. It needs a specific instantiation through its library for puppeteer.

That shouldn't be the case, the overload of only adds helper methods on top of puppeteer.
Or did you find any specific issues? If that's the case, it would be good to know about it. 🙂

Also, there's a make target to generate a well structured Lambda Layer.

@devasur
Copy link
Contributor Author

devasur commented Oct 20, 2019

Let me describe the steps I am using now. I sure am missing something here. You should be able to help me along.

My deployed program does not have a direct dependency on 'chrome-aws-lambda' package. Loading of all required components I am doing using a layer and puppeteer-core.

  let getBrowser = async()=>{
    let puppeteer = null;
    let chromePath =  fs.existsSync('/opt/headless_shell') ? '/opt/headless_shell' : null;
    if(!chromePath){
        chromePath =  fs.existsSync('layer/headless_shell') ? 'layer/headless_shell' : null;
    }
    let options = {
        headless: true,        
        args: ['--no-sandbox', '--disable-gpu', '--single-process'],
    };
    console.dir(options)
    if(chromePath){
        puppeteer = require('puppeteer-core');;
        options.executablePath = chromePath
    }
    else{
        puppeteer = require('puppeteer');
        options={};
    }
    return puppeteer.launch(options);
  }

I am using a build script on this project to create a packaged chrome executable for chrome.

#!/bin/bash

set -e

rm -fr chrome-aws-lambda
git clone --depth=1 https://github.com/alixaxel/chrome-aws-lambda.git && \
cd chrome-aws-lambda && \
brotli --decompress --rm bin/chromium*.br && \
npm pack && \
mkdir -p nodejs/node_modules/chrome-aws-lambda/ && \
tar --directory nodejs/node_modules/chrome-aws-lambda/ --extract --file chrome-aws-lambda-*.tgz --strip-components=1 && \
rm chrome-aws-lambda-*.tgz

find bin -name "chromium*" -exec mv {} ../layer/headless_shell \;
chmod 755 ../layer/headless_shell

echo 'Layer created successfully!'

With @alixaxel 's 1.20.3 code the above scripts build a nice package that I can use w/o any problem with puppeteer-core and node8.10 AWS runtime.

To create additional library components, I used @alixaxel 's make file to create chrome10.zip into my 'layer' folder.

%.zip:
	mkdir -p nodejs/node_modules/chrome-aws-lambda/
	cd nodejs/ && npm install lambdafs@~1.3.0 puppeteer-core@~1.20.0 --no-bin-links --no-optional --no-package-lock --no-save --no-shrinkwrap && cd -
	npm pack
	tar --directory nodejs/node_modules/chrome-aws-lambda/ --extract --file chrome-aws-lambda-*.tgz --strip-components=1
	rm chrome-aws-lambda-*.tgz
	mkdir -p $(dir $@)
	zip -9 --filesync --move --recurse-paths $@ nodejs/

With this step, my layer/ folder now has two files.

/layer/headless_shell
/layer/chrome10.zip

When I deploy this combined layer with Node 10 AWS Runtime, puppeteer is unable to map Library paths. It is unable to load chrome and errors out with the following message.

Error: Failed to launch chrome!
/opt/headless_shell: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

@devasur
Copy link
Contributor Author

devasur commented Oct 22, 2019

I have submitted a PR with Node 10 compatibility.

@fartbagxp
Copy link

I ran into the same issue just now, and updated my script with the new build script that @devasur created in #16.

It works for me, and I've updated my script to utilize the new layer created as well.
I deleted my layer folder before running the build script and /layer/chrome10.zip is the only file generated, that seems like the only file needed deployment as a layer.

@Meekohi
Copy link

Meekohi commented Mar 16, 2020

Hit this today, node8 is deprecated.

@chicomcastro
Copy link

Now node10 is deprecated. I'm facing this error

An error occurred: PuppeteerDashorchestratorLambdaFunction - Resource handler returned message: "The runtime parameter of nodejs10.x is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (nodejs14.x) while creating or updating functions.

I'm trying to figure out how to work with newer node versions.

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