[Python] Run Headless Chrome on AWS Lambda

  1. Download and unzip serverless-chrome --Confirmed operation with the following chromium 64.0.3282.167

    • https://github.com/adieuadieu/serverless-chrome/releases/tag/v1.0.0-37
  2. Download and unzip the chrome driver --Checked with the following chromedriver_linux64.zip

    • https://chromedriver.storage.googleapis.com/index.html?path=2.37/
  3. Grant execution authority -- chmod 777 <downloaded file>

  4. Put the downloaded file in the chrome folder and zip it

  5. Upload the zip to the Lambda layer

  6. Upload selenium to Lambda layer --Refer to the following

    • https://qiita.com/mishimay/items/e107b685381cca0493bf
  7. Add the above two layers to your Lambda function

  8. Can be executed with code like below

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def lambda_handler(event, context):
    options = Options()
    options.binary_location = '/opt/chrome/headless-chromium'
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--single-process')
    options.add_argument('--disable-dev-shm-usage')

    browser = webdriver.Chrome('/opt/chrome/chromedriver', chrome_options=options)
    browser.get('https://www.google.com')
    title = browser.title
    browser.close()
    browser.quit()

    return {"title": title}

reference

https://blog.ikedaosushi.com/entry/2018/12/22/231421 https://qiita.com/nabehide/items/754eb7b7e9fff9a1047d

environment

macOS 10.15.4 Python 3.7.7

Recommended Posts

[Python] Run Headless Chrome on AWS Lambda
Run Python on Schedule on AWS Lambda
Periodically run a python program on AWS Lambda
Python + Selenium + Headless Chromium with aws lambda
Run mysqlclient on Lambda
Modules cannot be imported in Python on EC2 run from AWS Lambda
Run Openpose on Python (Windows)
[Python] Scraping in AWS Lambda
Check types_map when using mimetypes on AWS Lambda (Python)
Run Tensorflow 2.x on Python 3.7
Support for Python 2.7 runtime on AWS Lambda (as of 2020.1)
Run unix command on python
I want to AWS Lambda with Python on Mac!
Run YOLO v3 on AWS v2
Run YOLO v3 on AWS
Posted as an attachment to Slack on AWS Lambda (Python)
Post images of Papillon regularly on Python + AWS Lambda + Slack
[Python] Allow pip3 packages to be imported on AWS Lambda
Summary if using AWS Lambda (Python)
Write AWS Lambda function in Python
Run TensorFlow Docker Image on Python3
Notify HipChat with AWS Lambda (Python)
Periodically run Python on Heroku Scheduler
How to make AWS Lambda Layers when running selenium × chrome on AWS Lambda
xgboost (python) on EC2 Spot instance environment prepared by AWS Lambda
Things to note when running Python on EC2 from AWS Lambda
Best practice for logging in JSON format on AWS Lambda / Python
[AWS] Using ini files with Lambda [Python]
Run servo with Python on ESP32 (Windows)
Run TensorFlow on a GPU instance on AWS
[Python] Run Flask on Google App Engine
Install python library on Lambda using [/ tmp]
Run AzureKinect in Python on Christmas Eve.
Run servomotor on Raspberry Pi 3 using python
Run Python code on A2019 Community Edition
Connect to s3 with AWS Lambda Python
Run Python in C ++ on Visual Studio 2017
Run python wsgi server on NGINX Unit
Steps to run Google Chrome headless on EC2 Ubuntu and take screenshots
Install and run Python3.5 + NumPy + SciPy on Windows 10
Put MicroPython on Windows to run ESP32 on Python
[2020 version] How to install Python3 on AWS EC2
Python on Windows
twitter on python3
Run Python YOLOv3 in C ++ on Visual Studio 2017
Python development on Ubuntu on AWS EC2 (using JupyterLab)
How to run MeCab on Ubuntu 18.04 LTS Python
LINE BOT with Python + AWS Lambda + API Gateway
Run Zookeeper x python (kazoo) on Mac OS X
python on mac
Jinja2 2.9.6 does not work on Lambda Python 3 series
Jupyter on AWS
Run pip install on MacOS Python 3.7 or later
Summary of points I was addicted to running Selenium on AWS Lambda (python)
[AWS / Lambda] How to load Python external library
Run Flask on CentOS with python3.4, Gunicorn + Nginx.
(For myself) AWS_Flask_3 (Install / Run Flask on AWS)
Summary of studying Python to use AWS Lambda
Python on Windbg
Amazon API Gateway and AWS Lambda Python version
TensorFlow: Run data learned in Python on Android