shelfio / chrome-aws-lambda-layer

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

How to use this layer? #8

Closed serverlesspolska closed 4 years ago

serverlesspolska commented 4 years ago

Hi,

Could you please explain how to use this layer? I have added

    layers:
       - arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:8

in my serverless.yml And I'm using exactly the same code from https://github.com/alixaxel/chrome-aws-lambda#usage

Unfortunately, I get

ERROR   Unhandled Promise Rejection 

{
  "errorType": "Runtime.UnhandledPromiseRejection",
  "errorMessage": "Error: Error: ENOENT: no such file or directory, open '//../bin/chromium.br'",
  "reason": {
    "errorType": "Error",
    "errorMessage": "Error: ENOENT: no such file or directory, open '//../bin/chromium.br'",
    "stack": ["Error: Error: ENOENT: no such file or directory, open '//../bin/chromium.br'", "    at fetchPageSource (/var/task/src/harvest/webpack:/home/pawel/serverless/leniuch/src/harvest/fetchLinksFromWebsite.js:34:11)"]
  },
  "promise": {},
  "stack": ["Runtime.UnhandledPromiseRejection: Error: Error: ENOENT: no such file or directory, open '//../bin/chromium.br'", "    at process.on (/var/runtime/index.js:37:15)", "    at process.emit (events.js:198:13)", "    at process.emit (/var/task/src/harvest/webpack:/home/pawel/serverless/leniuch/node_modules/source-map-support/source-map-support.js:485:1)", "    at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)", "    at process._tickCallback (internal/process/next_tick.js:69:34)"]
}
vladholubiev commented 4 years ago

Looking at this path /home/pawel/serverless/leniuch/src/harvest/fetchLinksFromWebsite.js:34:11 I'm assuming you're trying to run code locally? If that's the case, the problem might be with the tool you use to run lambdas locally, it should support Lambda Layers and unpack them at runtime

serverlesspolska commented 4 years ago

Hi @vladgolubev,

this is actually from the JavaScript source maps - I'm using a webpack to transpile the code.

Code is executed on AWS Lambda

serverlesspolska commented 4 years ago

OK, it just doesn't work with a webpack.

For reference I am using

plugins:
  - serverless-bundle
loganpowell commented 4 years ago

Thank you for publishing these layers!

Sorry to ping on a closed issue, but I'm also trying to leverage one of these layers and am getting errors. Are there any guides as how to pair this up with the appropriate puppeteer version on AWS as a layer? Are there any security settings I may need to set up? Any tips/suggestions would be greatly appreciated :)

vladholubiev commented 4 years ago

@loganpowell would be helpful if you post one of those errors. Otherwise, the code from https://github.com/alixaxel/chrome-aws-lambda#usage should work out-of-the-box

loganpowell commented 4 years ago

@vladgolubev thank you for the quick follow up!

I would post the error, but the actual aws logging console is error'ing out (so no error logs are being produced).

Thank you for that link. Just to clarify, do I still have to npm install chrome-aws-lambda puppeteer-core --save-prod to leverage the layer or do I leave any/both of them out and let the layer fulfill the references/imports

const chromium = require('chrome-aws-lambda');
...

in my code?

vladholubiev commented 4 years ago

@loganpowell you don't need to install those dependencies, they are inside layer already