6

I am using this part of code to run selenium on aws lambda with runtime 3.8

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def handler(event, context):
    options = Options()
    options.binary_location = '/opt/headless-chromium'
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--single-process')
    options.add_argument('--disable-dev-shm-usage')

    driver = webdriver.Chrome('/opt/chromedriver',chrome_options=options)
    driver.get('https://www.google.com/')

    driver.close();
    driver.quit();

    response = {
        "statusCode": 200,
        "body": "Selenium Headless Chrome Initialized"
    }

    return response

but it gives /opt/chromedriver unexpectedly exited. Status code was: 127 error every time i run it. any idea about this? is selenium compatible with python3.8

  • How have you added these binaries to the Lambda execution environment? They are not the typical paths used by layers. Are you using you own container deployment? – Mark Sailes Jun 21 '22 at 11:59
  • @MarkSailes Yes I have added binaries and I am using container deployment. The issue is I have added Selenium , chromium and headless-chromium as layer , the same thing works with python 3.7 but gives error when i change runtiome to python3.8 – Sparsh Rawat Jun 21 '22 at 14:04
  • 1
    https://stackoverflow.com/questions/66328444/aws-lambda-selenium-headless-chrome-incompatible-with-python-3-8 -> this thread with the same compatibility issue discussion says that there is an issue with python3.8 compatibility so I just want to confirm that if it is actually true or merely random assumptions – Sparsh Rawat Jun 21 '22 at 14:14

1 Answers1

2

AWS gives us the option to set up specific runtime for each lambda function. working perfectly in python 3.7.