Home > Back-end >  Chrome Driver issue in Lambda function
Chrome Driver issue in Lambda function

Time:02-21

I am using below code in AWS Lambda Function

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    from selenium.webdriver.chrome.options import Options
def lambda_handler(event, context):
    options = Options()
    options.binary_location = '/opt/headless-chromium'
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--start-maximized')
    options.add_argument('--start-fullscreen')
    options.add_argument('--single-process')
    options.add_argument('--disable-dev-shm-usage')
    driver = webdriver.Chrome('/opt/chromedriver', options=options)

Error:

[ERROR] WebDriverException: Message: Service /opt/chromedriver unexpectedly exited. Status code was: 127

Traceback (most recent call last):   File "/var/task/lambda_function.py", line 27, in lambda_handler     driver = webdriver.Chrome('/opt/chromedriver', options=options)   File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in init     super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog",   File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 90, in init     self.service.start()   File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 98, in start     self.assert_process_still_running()   File "/opt/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running

Note : My Layer structure is below in zip file and using curl command to get linux drivers for lambda

curl -SL https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip > chromedriver.zip
curl -SL https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-41/stable-headless-chromium-amazonlinux-2017-03.zip > headless-chromium.zip 

enter image description here

CodePudding user response:

I used python3.7 and used zip package which is available in below link

Working layer for me

  • Related