Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
umihico committed Mar 12, 2021
0 parents commit 24f72b4
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
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" ]
10 changes: 10 additions & 0 deletions Makefile
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 '{}'
22 changes: 22 additions & 0 deletions README.md
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.
17 changes: 17 additions & 0 deletions serverless.yml
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
16 changes: 16 additions & 0 deletions test.py
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

0 comments on commit 24f72b4

Please sign in to comment.