JupiterOne / playwright-aws-lambda

Support for running Microsoft's Playwright on AWS Lambda and Google Cloud Functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lambda deployed with CDK - ENOENT: no such file or directory, open '/var/task/bin/chromium.br

phstc opened this issue · comments

I'm deploying a NodejsFunction, and I'm getting this error invoking my lambda:

ENOENT: no such file or directory, open '/var/task/bin/chromium.br

image

NodejsFunction uses esbuild that compresses the lambda code. Therefore, missing chromium binaries.

Is anyone doing something similar with a NodejsFunction that could share some snippets?

Yes I feel like a step is missing here

@revmischa now it's working for me, but I don't remember exactly what unlocked me, I forgot to update back this issue once it started to work.

What I have now:

Lambda layer contents:

npm install --prefix layer/nodejs -s chrome-aws-lambda playwright-core playwright-aws-lambda 

CDK:

const layer = new lambda.LayerVersion(this, "ChromeLayer", {
  // run npm install --prefix layer/nodejs -s chrome-aws-lambda playwright-core playwright-aws-lambda 
  code: lambda.Code.fromAsset("./layer"),
});

new NodejsFunction(scope, id, {
  runtime: lambda.Runtime.NODEJS_16_X,
  memorySize: 1024,
  bundling: {
    externalModules: [
      "chrome-aws-lambda",
      "playwright-core",
      "playwright-aws-lambda",
    ],
  },
  layers: [layer],
  timeout: Duration.minutes(15),
});

then on a lambda:

const playwright = require('playwright-aws-lambda');

// ...

const browser = await playwright.launchChromium({ headless: true });

This is what I did for bundling settings in Serverless Stack:

 hooks: {
          beforeBuild: async (props, outDir) => {
            // create bin folder
            const binDir = path.join(outDir, "bin")
            if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true })
          },
        },
        copyFiles: [
          {
            from: "backend/node_modules/playwright-aws-lambda/dist/src/bin/aws.tar.br",
            to: "./bin/aws.tar.br",
          },
          {
            from: "backend/node_modules/playwright-aws-lambda/dist/src/bin/chromium.br",
            to: "./bin/chromium.br",
          },
          {
            from: "backend/node_modules/playwright-aws-lambda/dist/src/bin/swiftshader.tar.br",
            to: "./bin/swiftshader.tar.br",
          },
        ],

but it's quite hacky

Hello @phstc @revmischa, I am facing the "almost" same issue here:
ENOENT: no such file or directory, open '/var/task/packages/functions/src/bin/[chromium.br](http://chromium.br/)'
I am using SST with playwright-aws-lambda, it is working perfectly locally (with the sst dev command), but having this issue when deployed to prod:
image
Any idea on what could be happening?