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

[BUG] Error on AWS, cannot find chromium.br file #67

Closed
kamilkp opened this issue Oct 21, 2019 · 10 comments
Closed

[BUG] Error on AWS, cannot find chromium.br file #67

kamilkp opened this issue Oct 21, 2019 · 10 comments
Assignees
Labels
bug Something isn't working invalid This doesn't seem right question Further information is requested

Comments

@kamilkp
Copy link

kamilkp commented Oct 21, 2019

Trying to get a basic example to work on AWS lambda and here's the error I get: Seems like chromium is not installed on the OS there?

Environment

  • chrome-aws-lambda Version: 1.20.3
  • puppeteer / puppeteer-core Version: 1.20.0
  • OS: AWS Lambda
  • Node.js Version: 10.x
  • Lambda / GCF Runtime: ?

Expected Behavior

Should work

Current Behavior

Error: ENOENT: no such file or directory, open 'node_modules/chrome-aws-lambda/source/../bin/chromium.br'

Possible Solution

Steps to Reproduce

@kamilkp kamilkp added the bug Something isn't working label Oct 21, 2019
@alixaxel alixaxel added the question Further information is requested label Oct 21, 2019
@alixaxel
Copy link
Owner

This shouldn't happen... Are you doing something special with your Lambda deployment?
Could you share code and/or steps to reproduce?

image

If you attach the deployment package of your Lambda it would be much easier to debug.

@kamilkp
Copy link
Author

kamilkp commented Oct 21, 2019

well I just deploy it with serverless. This is it's code:

import chromium from 'chrome-aws-lambda';
import puppeteer from 'puppeteer-core';

export default async function print({
  url
}) {
  let browser = await puppeteer.launch({
    args: chromium.args,
    defaultViewport: chromium.defaultViewport,
    executablePath: await chromium.executablePath,
    headless: chromium.headless,
  });

  const page = await browser.newPage();

  await page.goto(url, {
    waitUntil: ['networkidle0', 'load', 'domcontentloaded'],
  });

  const result = await page.pdf({
    printBackground: true,
    format: 'A4',
    displayHeaderFooter: false,
  });

  return result.data;
}

Here is a portion of my serverless.yml file:

service: sling-lambda-print-2

provider:
  name: aws
  runtime: nodejs10.x
  stage: dev
  region: us-east-1
  environment:
    DEBUG: false
    LOGGING: true
  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:*
      Resource: "arn:aws:s3:::${self:custom.bucket}/*"
    - Effect: Allow
      Action:
        - s3:ListBucket
      Resource: "arn:aws:s3:::${self:custom.bucket}"
    - Effect: Allow
      Action:
        - lambda:InvokeFunction
        - lambda:InvokeAsync
      Resource: "*"

plugins:
  - serverless-webpack

custom:
  chrome:
    flags:
      - --hide-scrollbars
    functions:
      - render
  bucket: headless-print-files

functions:
  render:
    description: Render pdf
    memorySize: 2536
    timeout: 300 # AWS Lambda limitation
    handler: src/handlers/render.default
    environment:
      DEBUG: false
      BUCKET: ${self:custom.bucket}
      FONTCONFIG_PATH: /var/task/fonts

resources:
  Resources:
    ApiGatewayRestApi:
      Properties:
        BinaryMediaTypes:
          - "*/*"

@alixaxel
Copy link
Owner

@kamilkp I can't provide support for serverless, you should open a issue with them, I suspect that serverless-webpack might be the culprit, but without the deployment package I can't be sure.

Also not sure where this configuration is original from, but I don't think you should be setting FONTCONFIG_PATH and I also don't think --hide-scrollbars has any effect with just the code you shared. Closing this as it doesn't seem to be an issue with this project but rather something else.

@alixaxel alixaxel added the invalid This doesn't seem right label Oct 21, 2019
@kamilkp
Copy link
Author

kamilkp commented Oct 22, 2019

In case someone finds this issue in the future here's what I did to solve it:

  1. Add chrome-aws-lamdba as an external in webpack config:
externals: ['aws-sdk', 'chrome-aws-lambda'],
  1. Upload the chrome-aws-lambda layer as an AWS Lambda Layer via AWS console according to these instructions: https://github.com/alixaxel/chrome-aws-lambda#aws-lambda-layer

  2. Specify in serverless.yml which function should use this layer:

funcitons:
  your_function:
    layers:
      - arn:aws:lambda:<region>:<id>:layer:<name of layer>:<revision>

@kamilkp
Copy link
Author

kamilkp commented Oct 22, 2019

@alixaxel might be worth adding this to your readme maybe? ^

@shellscape
Copy link

@alixaxel I second the suggestion from @kamilkp to add the note about externals to the instructions.

@mithundas79
Copy link

mithundas79 commented Aug 19, 2020

'chrome-aws-lambda'

I am following this instruction with the framework version 1.78.1 and serverless-webpack@latest

When I overide my externals variables in webpack.config.js as shown above, I get following error on deploy

ERROR in ./node_modules/handlebars/lib/index.js
Module not found: Error: Can't resolve '../dist/cjs/handlebars' in '/home/mithun/Workspace/boltinsight-lambdas/htmltopdf_service/node_modules/handlebars/lib'
 @ ./node_modules/handlebars/lib/index.js 7:17-50
 @ ./handler.ts

ERROR in ./node_modules/handlebars/lib/index.js
Module not found: Error: Can't resolve '../dist/cjs/handlebars/compiler/printer' in '/home/mithun/Workspace/boltinsight-lambdas/htmltopdf_service/node_modules/handlebars/lib'

So I keep externals as externals: [nodeExternals()]
and in serverless.yml file I do following

custom:
  webpack:
    webpackConfig: webpack.config.js
    includeModules:
      forceExclude:
        - chrome-aws-lambda

This makes sure the chrome-aws-lambda module is not bundle... however when i deploy and run the code I get
Access Denied

@andurmon
Copy link

@kamilkp Could you please share the contents of the .zip file you loaded to the chrome-aws-lambda layer? im not sure what contents to load to the layer

@JobaDiniz
Copy link

JobaDiniz commented Feb 4, 2023

how do I configure SAM to upload the chrome binaries needed on sam build->sam deploy?

@avijit1258
Copy link

In case someone finds this issue in the future here's what I did to solve it:

  1. Add chrome-aws-lamdba as an external in webpack config:
externals: ['aws-sdk', 'chrome-aws-lambda'],
  1. Upload the chrome-aws-lambda layer as an AWS Lambda Layer via AWS console according to these instructions: https://github.com/alixaxel/chrome-aws-lambda#aws-lambda-layer
  2. Specify in serverless.yml which function should use this layer:
funcitons:
  your_function:
    layers:
      - arn:aws:lambda:<region>:<id>:layer:<name of layer>:<revision>

What can be done when not using web pack for externals?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants