diff --git a/Dockerfile b/Dockerfile index e3a226b..feebd7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,17 @@ FROM public.ecr.aws/lambda/python:3.9 as build RUN yum install -y unzip && \ - curl -SL https://chromedriver.storage.googleapis.com/2.43/chromedriver_linux64.zip > /tmp/chromedriver.zip && \ - curl -SL https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-55/stable-headless-chromium-amazonlinux-2017-03.zip > /tmp/headless-chromium.zip && \ + curl -Lo "/tmp/chromedriver.zip" "https://chromedriver.storage.googleapis.com/89.0.4389.23/chromedriver_linux64.zip" && \ + curl -Lo "/tmp/chrome-linux.zip" "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F843831%2Fchrome-linux.zip?alt=media" && \ unzip /tmp/chromedriver.zip -d /opt/ && \ - unzip /tmp/headless-chromium.zip -d /opt/ + unzip /tmp/chrome-linux.zip -d /opt/ FROM public.ecr.aws/lambda/python:3.9 -RUN yum install -y https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm +RUN yum install 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 -y RUN pip install selenium -COPY --from=build /opt/headless-chromium /opt/ +COPY --from=build /opt/chrome-linux /opt/chrome COPY --from=build /opt/chromedriver /opt/ COPY test.py ./ CMD [ "test.handler" ] diff --git a/README.md b/README.md index 868a754..b73c04b 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,9 @@ This is minimum demo of headless chrome and selenium on container image on AWS L This image goes with these versions. - Python 3.9 -- serverless-chrome v1.0.0-55 - - chromium 69.0.3497.81 (stable channel) for amazonlinux:2017.03 -- chromedriver 2.43 -- selenium 3.141.0 (latest) +- chromium 89.0.4389.47 +- chromedriver 89.0.4389.23 +- selenium 4.0.0 ### Running the demo diff --git a/test.py b/test.py index 726f752..6629e5c 100644 --- a/test.py +++ b/test.py @@ -3,14 +3,18 @@ def handler(event=None, context=None): options = webdriver.ChromeOptions() - options.binary_location = "/opt/headless-chromium" + options.binary_location = '/opt/chrome/chrome' options.add_argument('--headless') 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("--user-data-dir=/tmp/chrome-user-data") + options.add_argument("--remote-debugging-port=9222") chrome = webdriver.Chrome("/opt/chromedriver", options=options) - chrome.get("https://umihi.co/") + chrome.get("https://example.com/") return chrome.find_element_by_xpath("//html").text