Closed
Description
I copied content from your dockerfile and copied the selenium config code from the repo. While testing on Lambda I am getting this error: [Errno 8] Exec format error: '/opt/chromedriver'""
Edit: Full Error Log:
{
"errorMessage": "[Errno 8] Exec format error: '/opt/chromedriver'",
"errorType": "OSError",
"requestId": "38abf731-f707-48d5-8608-b56fb81a71dd",
"stackTrace": [
" File \"/var/task/main.py\", line 24, in handler\n chrome = webdriver.Chrome(options=options, service=service)\n",
" File \"/var/lang/lib/python3.12/site-packages/selenium/webdriver/chrome/webdriver.py\", line 45, in __init__\n super().__init__(\n",
" File \"/var/lang/lib/python3.12/site-packages/selenium/webdriver/chromium/webdriver.py\", line 55, in __init__\n self.service.start()\n",
" File \"/var/lang/lib/python3.12/site-packages/selenium/webdriver/common/service.py\", line 101, in start\n self._start_process(self._path)\n",
" File \"/var/lang/lib/python3.12/site-packages/selenium/webdriver/common/service.py\", line 211, in _start_process\n self.process = subprocess.Popen(\n",
" File \"/var/lang/lib/python3.12/subprocess.py\", line 1026, in __init__\n self._execute_child(args, executable, preexec_fn, close_fds,\n",
" File \"/var/lang/lib/python3.12/subprocess.py\", line 1955, in _execute_child\n raise child_exception_type(errno_num, err_msg, err_filename)\n"
]
}
requirements.txt
boto3==1.26.90
requests==2.28.2
beautifulsoup4==4.11.2
webdriver-manager==4.0.0
selenium==4.25.0
DockerFile
FROM public.ecr.aws/lambda/python@sha256:e0eed1c4a447cfadac34369181090b9d5616d52f385959e08c4e8f942a668a5d as build
RUN dnf install -y unzip && \
curl -Lo "/tmp/chromedriver-linux64.zip" "https://storage.googleapis.com/chrome-for-testing-public/129.0.6668.100/linux64/chromedriver-linux64.zip" && \
curl -Lo "/tmp/chrome-linux64.zip" "https://storage.googleapis.com/chrome-for-testing-public/129.0.6668.100/linux64/chrome-linux64.zip" && \
unzip /tmp/chromedriver-linux64.zip -d /opt/ && \
unzip /tmp/chrome-linux64.zip -d /opt/
FROM public.ecr.aws/lambda/python@sha256:e0eed1c4a447cfadac34369181090b9d5616d52f385959e08c4e8f942a668a5d
RUN dnf install -y atk cups-libs gtk3 libXcomposite alsa-lib \
libXcursor libXdamage libXext libXi libXrandr libXScrnSaver \
libXtst pango at-spi2-atk libXt xorg-x11-server-Xvfb \
xorg-x11-xauth dbus-glib dbus-glib-devel nss mesa-libgbm
COPY --from=build /opt/chrome-linux64 /opt/chrome
COPY --from=build /opt/chromedriver-linux64 /opt/
COPY requirements.txt ./
COPY lambda.py ./
COPY eloquii.py ./
RUN pip install -r requirements.txt
CMD [ "lambda.lambda_handler" ]
Eloquii.py
import boto3
from selenium import webdriver
from tempfile import mkdtemp
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
import time
def scrape_product(url, category):
# Set up Selenium WebDriver
options = webdriver.ChromeOptions()
service = webdriver.ChromeService("/opt/chromedriver")
options.binary_location = '/opt/chrome/chrome'
options.add_argument("--headless=new")
options.add_argument('--no-sandbox')
options.add_argument("--disable-gpu")
options.add_argument("--window-size=1280x1696")
options.add_argument("--single-process")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-dev-tools")
options.add_argument("--no-zygote")
options.add_argument(f"--user-data-dir={mkdtemp()}")
options.add_argument(f"--data-path={mkdtemp()}")
options.add_argument(f"--disk-cache-dir={mkdtemp()}")
options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome(options=options, service=service)
driver.get(url)
time.sleep(2)
# Get the page source and parse it
product_page_content = driver.page_source
product_soup = BeautifulSoup(product_page_content, 'html.parser')
What am I doing wrong ?? How do I successfully use selenium in Lambda?
Metadata
Metadata
Assignees
Labels
No labels