shelfio / chrome-aws-lambda-layer

58 MB Google Chrome to fit inside AWS Lambda Layer compressed with Brotli
MIT License
637 stars 45 forks source link

Node 16.x is supported? #275 #42

Closed outaTiME closed 2 years ago

outaTiME commented 2 years ago

I am having the following error when I try to run my lambda with node 16.x, does anyone else get this?

 "Failed to launch the browser process!\n/tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory\n\n\nTROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md\n"
kosanna commented 2 years ago

Have you tried downgrading? Did it work? Going to try with 14 and see if it fixes the issue 🤔

UPD: Looks like it worked. At least no missing libs issue anymore. But now I have browser hanging :D Fun

vladholubiev commented 2 years ago

Right, this layer depends on https://github.com/alixaxel/chrome-aws-lambda and the upstream repo hasn't been updated to support Node 16 yet.

I see @outaTiME already raise the issue there: https://github.com/alixaxel/chrome-aws-lambda/issues/275

vladholubiev commented 2 years ago

I've just published a new layer version 27 that has the latest Chromium and Node 16 support!

Thanks again for pointing this out!

outaTiME commented 2 years ago

Hi @vladgolubev, for some reason the new layer does not work for me, it gives me the following error:

{
    "error type": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module '@sparticuz/chrome-aws-lambda'\nRequire stack:\n- /var/task/src/subscribers/social-notify.js\n- /var/ runtime/index .mjs",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module '@sparticuz/chrome-aws-lambda'",
        "Require stack:",
        "- /var/task/src/subscribers/social-notify.js",
        "- /var/runtime/index.mjs",
        " at _loadUserApp (file:///var/runtime/index.mjs:726:17)",
        " at async Object.module.exports.load (file:///var/runtime/index.mjs:741:21)",
        " in async file:///var/runtime/index.mjs:781:15",
        " in async file: ///var/runtime/index.mjs:4:1"
    ]
}

but if I manually download and configure the artifact (https://github.com/Sparticuz/chrome-aws-lambda/suites/6829349165/artifacts/263061533) it works like a charm,

could it be that you have left some misconfigured route when you did the deployment?

vladholubiev commented 2 years ago

@outaTiME hm, strange, what I did is just package the same artifact zip as is into a layer

Maybe it's b/c zip has extra nodejs folder inside?

I've just published v28 with that change, could you please try it ?

outaTiME commented 2 years ago

Unfortunately using 28 throws the same error, locally my structure for the layer is as follows:

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module '@sparticuz/chrome-aws-lambda'\nRequire stack:\n- /var/task/packages/api/src/subscribers/social-notify.js\n- /var/runtime/index.mjs",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module '@sparticuz/chrome-aws-lambda'",
        "Require stack:",
        "- /var/task/packages/api/src/subscribers/social-notify.js",
        "- /var/runtime/index.mjs",
        "    at _loadUserApp (file:///var/runtime/index.mjs:726:17)",
        "    at async Object.module.exports.load (file:///var/runtime/index.mjs:741:21)",
        "    at async file:///var/runtime/index.mjs:781:15",
        "    at async file:///var/runtime/index.mjs:4:1"
    ]
}

the error message gives the feeling that the @sparticuz/chrome-aws-lambda package is not available within the layer (or at least within that file structure),

and as I told you before, I simply unzipped the artifact in a folder called "chrome":

image

I also tell you that I am using SST, I show you a little about the definition of my layer:

const layerArn =
  "arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:28";

  socialNotify: {
  function: {
    handler: 'src/subscribers/social-notify.handler',
    bundle: {
      externalModules: ['@sparticuz/chrome-aws-lambda'],
    },
    layers: [
      new lambda.LayerVersion(stack, 'ChromeLayer', {
        code: lambda.Code.fromAsset('packages/api/layers/chrome'),
      }),
      // commented out to leave the local layer which is the one that works
      // LayerVersion.fromLayerVersionArn(stack, "ChromeLayer", layerArn),
    ],
    // ~30s
    timeout: '1 minute',
  },
  cdk: {
    subscription: {
      filterPolicy: {
        event: SubscriptionFilter.stringFilter({
          allowlist: ['social-notify'],
        }),
      },
    },
  },
},
vladholubiev commented 2 years ago

So apparently, embedding node_modules inside nodejs folder is required, so I reverted that change in the v29.

I'm not familiar with SST so maybe the issue is with it somehow?

outaTiME commented 2 years ago

Regardless of SST and the layer has to have the following structure nodejs/node_modules (https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html), I just did a download of your layer 28 as follows:

$ aws lambda get-layer-version-by-arn --arn "arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:28"

and looking at the contents I see that the nodejs folder does not exist, unlike layer 25, which does have one, I am enclosing a reduced comparison of the contents between both versions:

image

btw, you can also see some dirt in the zip, like the descriptors (__MACOSX) which can possibly be removed to make everything much cleaner

vladholubiev commented 2 years ago

@outaTiME what about layer version 29? it should have the nodejs enclosing folder now.

Thanks for pointing out the dirt. I can see that + some other stuff to be removed (like .d.ts files or browser build of libraries)

outaTiME commented 2 years ago

yay, @vladgolubev, the layer 29 works amazing 🚀

Thank you very much, for all your work and support !!!

vladholubiev commented 2 years ago

You're welcome! And thank you too!

v30 w/o junk (~2 MB of junk removed) will be published as soon as Docker Hub will get up 🙂

https://app.circleci.com/pipelines/github/shelfio/chrome-aws-lambda-layer/71/workflows/256fa5ce-a50f-4f32-a892-6e2bdadb8112

outaTiME commented 2 years ago

Great, I'm trying a new layer 30 as soon as it's available, thanks again !!!

outaTiME commented 2 years ago

I just downloaded layer 30, and I keep seeing dirt in the __MACOSX folders, could it be?

vladholubiev commented 2 years ago

Automated zipping via create-zip.sh as turns out macOS will create that junk if you zip from UI.

Now it shouldn't be!

I've published v31 and I don't see any that junk anymore!

CleanShot 2022-06-13 at 16 59 50@2x
outaTiME commented 2 years ago

sweet, everything works amazing, thanks again @vladgolubev !!!