Firefox Selenium on AWS Lambda: binary is not a Firefox executable

Viewed 723

I'm trying to use Firefox WebDriver with Selenium on AWS Lambda using three lambda layers:

  1. geckodriver
  2. python selenium
  3. firefox binary (https://ftp.mozilla.org/pub/firefox/releases/69.0.1/linux-x86_64/en-GB/firefox-69.0.1.tar.bz2)

This is my code:

import json
from shutil import copyfile
import os
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary



def webdriver_permissions(origin_path, destiny_path):

   ''' The geckodriver and firefox binaries are set in the lambda
   function through a lambda layer. However, by default these files are saved
   in '/opt' folder and hence they are not executable. This function copy the
   binaries to '/tmp' folder and grant them with executable permissions '''


   copyfile(origin_path, destiny_path)
   os.chmod(destiny_path, 0o775)

def lambda_handler(event, context):

    webdriver_permissions('/opt/geckodriver','/tmp/geckodriver')
    webdriver_permissions('/opt/firefox/firefox','/tmp/firefox')

    options = Options()
    options.headless = True
    options.binary =  FirefoxBinary('/tmp/firefox')


    driver = webdriver.Firefox(
        options=options,
        executable_path="/tmp/geckodriver",
        log_path="/tmp/geckodriver.log"
    )

  url = 'foo'
  driver.get(url)

When I run the code the geckodriver portions of the code works fine, but when I reach the binary option this error appears:

"errorMessage": "Message: binary is not a Firefox executable\n"

I've tried almost everything:

  • using different versions of firefox
  • using a file named "firefox-bin" that also exist in the folder, instead of "firefox"
  • not changing the binaries to /tmp

Any suggestion with that?

0 Answers
Related