File tree Expand file tree Collapse file tree 5 files changed +79
-0
lines changed Expand file tree Collapse file tree 5 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ FROM public.ecr.aws/lambda/python:3.7 as build
2+ RUN mkdir -p /opt/bin/ && \
3+ mkdir -p /tmp/downloads && \
4+ curl -SL https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip > /tmp/downloads/chromedriver.zip && \
5+ curl -SL https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-37/stable-headless-chromium-amazonlinux-2017-03.zip > /tmp/downloads/headless-chromium.zip && \
6+ unzip /tmp/downloads/chromedriver.zip -d /opt/bin/ && \
7+ unzip /tmp/downloads/headless-chromium.zip -d /opt/bin/
8+
9+ FROM public.ecr.aws/lambda/python:3.7
10+ RUN mkdir -p /opt/bin && pip install selenium
11+ COPY --from=build /opt/bin/headless-chromium /opt/bin/
12+ COPY --from=build /opt/bin/chromedriver /opt/bin/
13+ COPY test.py ./
14+ CMD [ "test.handler" ]
Original file line number Diff line number Diff line change 1+ # This is just my personal scripts for development
2+
3+ build :
4+ docker build -t docker-selenium-lambda .
5+ bash :
6+ docker run --rm -it --entrypoint ' ' docker-selenium-lambda bash
7+ run :
8+ docker run -p 7000:8080 --rm -it docker-selenium-lambda
9+ test :
10+ curl -XPOST " http://localhost:7000/2015-03-31/functions/function/invocations" -d ' {}'
Original file line number Diff line number Diff line change 1+ # docker-selenium-lambda
2+
3+ This is minimum demo of headless chrome and selenium on container image on AWS Lambda
4+
5+ This image goes with these versions.
6+
7+ - Python 3.7
8+ - serverless-chrome v1.0.0-37
9+ - chromedriver 2.37
10+ - selenium 3.141.0 (latest)
11+
12+ ### Running the demo
13+
14+ ``` bash
15+ $ YOUR_REGION=ap-northeast-1 # your region
16+ $ sls deploy --region $YOUR_REGION
17+ $ sls invoke -f server --region $YOUR_REGION
18+ ```
19+
20+ ### Contribution
21+
22+ I'm trying run latest Chrome but having difficulties. Please check out other branches and issues.
Original file line number Diff line number Diff line change 1+ service : docker-selenium-lambda
2+
3+ provider :
4+ name : aws
5+ stage : ${opt:stage, 'prod'}
6+ region : ${opt:region}
7+ ecr :
8+ images :
9+ test :
10+ path : ./
11+
12+ functions :
13+ server :
14+ timeout : 60
15+ memorySize : 2048
16+ image :
17+ name : test
Original file line number Diff line number Diff line change 1+ from selenium import webdriver
2+
3+
4+ def handler (event = None , context = None ):
5+ options = webdriver .ChromeOptions ()
6+ options .binary_location = "/opt/bin/headless-chromium"
7+ options .add_argument ('--headless' )
8+ options .add_argument ('--no-sandbox' )
9+ options .add_argument ("--disable-gpu" )
10+ options .add_argument ("--window-size=1280x1696" )
11+ options .add_argument ("--single-process" )
12+ options .add_argument ("--disable-dev-shm-usage" )
13+ chrome = webdriver .Chrome ("/opt/bin/chromedriver" ,
14+ options = options )
15+ chrome .get ("https://umihi.co/" )
16+ return chrome .find_element_by_xpath ("//html" ).text
You can’t perform that action at this time.
0 commit comments