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

/tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory #35

Closed wongmrdev closed 3 years ago

wongmrdev commented 3 years ago

Error

START RequestId: 82e73f60-75ce-43df-89d8-5646227193ff Version: $LATEST
2021-04-16T11:57:40.357Z    82e73f60-75ce-43df-89d8-5646227193ff    ERROR   Error: Failed to launch the browser process!
/tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
    at Interface.<anonymous> (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:183:68)
    at Interface.emit (events.js:327:22)
    at Interface.EventEmitter.emit (domain.js:467:12)
    at Interface.close (readline.js:424:8)
    at Socket.onend (readline.js:202:10)
    at Socket.emit (events.js:327:22)
    at Socket.EventEmitter.emit (domain.js:467:12)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
END RequestId: 82e73f60-75ce-43df-89d8-5646227193ff
REPORT RequestId: 82e73f60-75ce-43df-89d8-5646227193ff  Duration: 1560.81 ms    Billed Duration: 1561 ms    Memory Size: 10000 MB   Max Memory Used: 407 MB Init Duration: 379.09 ms

runtime: lambda layer: us-west-2: arn:aws:lambda:us-west-2:764866452798:layer:chrome-aws-lambda:20 lambda nodejs version 14.x

my code:


const chromium = require('chrome-aws-lambda');
const AWS = require('aws-sdk')
const preparePageForTests = async (page) => {
  const userAgent = 'Mozilla/5.0 (X11; Linux x86_64)' +
  'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Safari/537.36';

  await page.setUserAgent(userAgent);
}
const URL = 'https://www.costco.com/online-offers.html'

exports.handler = async (event, context, callback) => {
    let browser = null;
  try {
    browser = await chromium.puppeteer.launch({
      args: chromium.args,
      defaultViewport: chromium.defaultViewport,
      executablePath: await chromium.executablePath,
      headless: chromium.headless,
      ignoreHTTPSErrors: true,
    })
    const page = await browser.newPage()
    page.setDefaultNavigationTimeout(60000)
    await preparePageForTests(page)
    await page.goto(URL)
    await page.waitForSelector('li.eco-coupons')
    var coupons = await page.evaluate(() => {
      var ecoCouponNodeList = [...document.querySelectorAll('li.eco-coupons')]

      return ecoCouponNodeList 
    })
    await browser.close()

    return {result: coupons};
};
utkarshdalal commented 3 years ago

Having the same issue.

shawnostler commented 3 years ago

Switching from node14.x to node12.x fixed this issue for me.

Alec2435 commented 3 years ago

This is a bug with older versions of puppeteer, you'll need to use a layer with a newer revision of chrome-aws-lambda than the current version of this layer. (I also am publishing public chrome-aws-lambda layers here if you need)

terret commented 3 years ago

@ironmanCCT The solution to your issue is using the latest version of the chrome-aws-lambda layer as noticed by @Alec2435

Just update your lambda layer version from 20 arn:aws:lambda:us-west-2:764866452798:layer:chrome-aws-lambda:20 to 22 arn:aws:lambda:us-west-2:764866452798:layer:chrome-aws-lambda:22