-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 24f72b4
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM public.ecr.aws/lambda/python:3.7 as build | ||
RUN mkdir -p /opt/bin/ && \ | ||
mkdir -p /tmp/downloads && \ | ||
curl -SL https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip > /tmp/downloads/chromedriver.zip && \ | ||
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 && \ | ||
unzip /tmp/downloads/chromedriver.zip -d /opt/bin/ && \ | ||
unzip /tmp/downloads/headless-chromium.zip -d /opt/bin/ | ||
|
||
FROM public.ecr.aws/lambda/python:3.7 | ||
RUN mkdir -p /opt/bin && pip install selenium | ||
COPY --from=build /opt/bin/headless-chromium /opt/bin/ | ||
COPY --from=build /opt/bin/chromedriver /opt/bin/ | ||
COPY test.py ./ | ||
CMD [ "test.handler" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This is just my personal scripts for development | ||
|
||
build: | ||
docker build -t docker-selenium-lambda . | ||
bash: | ||
docker run --rm -it --entrypoint '' docker-selenium-lambda bash | ||
run: | ||
docker run -p 7000:8080 --rm -it docker-selenium-lambda | ||
test: | ||
curl -XPOST "http://localhost:7000/2015-03-31/functions/function/invocations" -d '{}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# docker-selenium-lambda | ||
|
||
This is minimum demo of headless chrome and selenium on container image on AWS Lambda | ||
|
||
This image goes with these versions. | ||
|
||
- Python 3.7 | ||
- serverless-chrome v1.0.0-37 | ||
- chromedriver 2.37 | ||
- selenium 3.141.0 (latest) | ||
|
||
### Running the demo | ||
|
||
```bash | ||
$ YOUR_REGION=ap-northeast-1 # your region | ||
$ sls deploy --region $YOUR_REGION | ||
$ sls invoke -f server --region $YOUR_REGION | ||
``` | ||
|
||
### Contribution | ||
|
||
I'm trying run latest Chrome but having difficulties. Please check out other branches and issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
service: docker-selenium-lambda | ||
|
||
provider: | ||
name: aws | ||
stage: ${opt:stage, 'prod'} | ||
region: ${opt:region} | ||
ecr: | ||
images: | ||
test: | ||
path: ./ | ||
|
||
functions: | ||
server: | ||
timeout: 60 | ||
memorySize: 2048 | ||
image: | ||
name: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from selenium import webdriver | ||
|
||
|
||
def handler(event=None, context=None): | ||
options = webdriver.ChromeOptions() | ||
options.binary_location = "/opt/bin/headless-chromium" | ||
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") | ||
chrome = webdriver.Chrome("/opt/bin/chromedriver", | ||
options=options) | ||
chrome.get("https://umihi.co/") | ||
return chrome.find_element_by_xpath("//html").text |