YusukeIwaki/puppeteer-ruby

Invalid channel: 'chrome'. Allowed channel is [\"chrome\", \"chrome-beta\", \"chrome-dev\ on AWS lambda

sp2410 opened this issue · 2 comments

Step To Reproduce / Observed behavior

  1. Install the gem on AWS Lambda using Serverless framework and serverless-ruby-layer plugin
  2. Install gem 'puppeteer-ruby', '~> 0.40.0' in Gemfile
  3. Add arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:25 as a lamda layer
  4. sls deploy to lambda
  5. Test run.

Any help is appreciated! Thank you

Error

Response

{
  "errorMessage": "Invalid channel: 'chrome'. Allowed channel is [\"chrome\", \"chrome-beta\", \"chrome-dev\"]",
  "errorType": "Function<ArgumentError>",
  "stackTrace": [
    "/opt/ruby/2.7.0/gems/puppeteer-ruby-0.40.0/lib/puppeteer/launcher/chrome.rb:294:in `executable_path_for_channel'",
    "/opt/ruby/2.7.0/gems/puppeteer-ruby-0.40.0/lib/puppeteer/launcher/chrome.rb:243:in `fallback_executable_path'",
    "/opt/ruby/2.7.0/gems/puppeteer-ruby-0.40.0/lib/puppeteer/launcher/chrome.rb:55:in `launch'",
    "/opt/ruby/2.7.0/gems/puppeteer-ruby-0.40.0/lib/puppeteer/puppeteer.rb:78:in `launch'",
    "/opt/ruby/2.7.0/gems/puppeteer-ruby-0.40.0/lib/puppeteer.rb:82:in `public_send'",
    "/opt/ruby/2.7.0/gems/puppeteer-ruby-0.40.0/lib/puppeteer.rb:82:in `block (3 levels) in <module:Puppeteer>'",
    "/var/task/src/lambda_function.rb:15:in `scrape!'",
    "/var/task/src/lambda_function.rb:24:in `handler'"
  ]
}

Expected behavior

require 'json'
require 'aws-sdk-s3'
require 'puppeteer-ruby
....
.
.
.
class PageScraper
  attr_accessor :page_link, :page_type

  def initialize(args)
    @page_link = args[:page_link];
    @page_type = args.fetch :page_type, "ITEM"
  end

  def scrape!
     Puppeteer.launch(headless: false) do |browser|
      page = browser.new_page
      page.goto(page_link, wait_until: 'domcontentloaded')
      page.content
    end
  end
end
....
.
.
.

Puppeteer.launch(headless: false) do |browser|
      page = browser.new_page
      page.goto(page_link, wait_until: 'domcontentloaded')
      page.content
end

should goto the page_link

Environment

  • ruby2.7 runtime on AWS lambda, Serverless Framework
  • Ruby local ruby 2.7.0p0

serverless.yml config

org:XXXXX
app: XXXXX-XXXX
name: aws-lambda-starter
component: aws-lambda

service: aws-ruby

provider:
  name: aws
  runtime: ruby2.7
  lambdaHashingVersion: 20201221

functions:
  sitemap-scraper:
    handler: src/lambda_function.handler
    layers: arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:25

plugins:
  - serverless-ruby-layer

Screen Shot 2022-01-17 at 3 45 49 PM

Thank you for the detailed bug report.

The error message Allowed channel is [\"chrome\", \"chrome-beta\", \"chrome-dev\"] is wrong and really confusing,
but the root cause seems that Chrome or Chromium is not installed with the executable name as below:

            'google-chrome-stable',
            'google-chrome',
            'chrome',
            'chromium-freeworld',
            'chromium-browser',
            'chromium',

The README of chrome-aws-lambda says that we have to specify executablePath parameter.
https://github.com/alixaxel/chrome-aws-lambda/blob/master/README.md?plain=1#L41

The logic for finding Chrome executable path is written with JS here.
https://github.com/alixaxel/chrome-aws-lambda/blob/master/source/index.ts#L147
And you would have to implement this logic with Ruby.

@sp2410 have you made it working? I'm trying to use arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:25 layer along with ruby-2.7 aws lambda environment, but getting chrome is not installed error.