Download and unzip serverless-chrome
--Confirmed operation with the following chromium 64.0.3282.167
Download and unzip the chrome driver
--Checked with the following chromedriver_linux64.zip
Grant execution authority
-- chmod 777 <downloaded file>
Put the downloaded file in the chrome
folder and zip it
Upload the zip to the Lambda layer
Upload selenium to Lambda layer --Refer to the following
Add the above two layers to your Lambda function
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}
https://blog.ikedaosushi.com/entry/2018/12/22/231421 https://qiita.com/nabehide/items/754eb7b7e9fff9a1047d
macOS 10.15.4 Python 3.7.7
Recommended Posts