Service /opt/chromedriver unexpectedly exited. Status code was: 127 Error when running selenium on aws lambda python3.8
Asked Answered
M

1

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

Milksop answered 21/6, 2022 at 8:44 Comment(3)
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?Mcglone
@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.8Milksop
#66328944 -> 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 assumptionsMilksop
M
1

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

Milksop answered 4/1, 2023 at 11:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.