adieuadieu / serverless-chrome

🌐 Run headless Chrome/Chromium on AWS Lambda
MIT License
2.87k stars 282 forks source link

Installing ChromeDriver and Headless Chrome Driver with latest version of Selenium #351

Open aleksandar-devedzic opened 8 months ago

aleksandar-devedzic commented 8 months ago

I am using Python and Selenium on AWS Lambdas for crawling. I have updated Python to 3.11 and Selenium to 4.18.0, but then my crawlers stopped working. This is the code for Selenium:


import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

def get_headless_driver():
    options = Options()
    service = Service(executable_path=r'/opt/chromedriver')
    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')
    options.add_argument('--window-size=1920x1080')
    options.add_argument('--start-maximized')

    return webdriver.Chrome(service=service, options=options)

def get_selenium_driver():
    return get_local_driver() if os.environ.get('STAGE') == 'local' else get_headless_driver()

This is the code for installing chrome driver:


#! /bin/bash

# exit when any command fails
set -e

NOCOLOR='\033[0m'
GREEN='\033[0;32m'

echo -e "\n${GREEN}Installing 'headless' layer dependencies...${NOCOLOR}\n"
sudo mkdir -p layers/headless && sudo chmod 777 layers/headless && cd layers/headless

# https://github.com/adieuadieu/serverless-chrome/issues/133
echo -e "\n${GREEN}Installing Chrome Driver v2.37...${NOCOLOR}\n"
sudo curl -SL https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip > chromedriver.zip
sudo chmod 755 chromedriver.zip
sudo unzip chromedriver.zip
sudo rm chromedriver.zip

echo -e "\n${GREEN}Installing Serverless Chrome v1.0.0-37...${NOCOLOR}\n"
sudo curl -SL https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-41/stable-headless-chromium-amazonlinux-2017-03.zip > headless-chromium.zip
sudo chmod 755 headless-chromium.zip
sudo unzip headless-chromium.zip
sudo rm headless-chromium.zip

cd ../../

I am getting this error:

Message: Service /opt/chromedriver unexpectedly exited. Status code was: 127

How should I fix this error? Should I also update the chromedriver and headless? What versions should I chose?

Darshit-dev commented 8 months ago

Same issue I am facing while runing on aws lambda

umihico commented 8 months ago

I hope my repository can be of some help

https://github.com/umihico/docker-selenium-lambda/