How to run automated (Selenium) Headless Chromium in AWS Lambda.
Read full article https://www.vittorionardone.it/en/2020/06/04/chromium-and-selenium-in-aws-lambda
An example about taking a full height screenshot of a given webpage in Python.
I’ve updated project to successfully use:
- Chromium 86.0.4240.0
- Chromedriver 86.0.4240.22.0
- Selenium 3.14
A Lambda Layer is used to include all required binaries and libs.
Selenium wrapper to get a full height screenshot of a given webpage. Code is in src/webdriver_screenshot.py
.
Lambda source code is in src/lambda_function.py
. It's a sample function using wrapper to get screenshot of a given URL. Fixed size and full height size screenshots are saved to a S3 bucket.
CloudFormation template to create Lambda stack. Please change WebSite
parameter to your favorite URL.
Run these commands in sequence:
make lambda-layer-build
to prepare archive for AWS Lambda Layer deploy (layer.zip)
make lambda-function-build
to prepare archive for AWS Lambda deploy (deploy.zip)
make BUCKET=<your_bucket_name> create-stack
to create CloudFormation stack (lambda function, layer and IAM role)
make docker-build
to prepare Docker image for AWS Lambda offline execution
make lambda-run
to execute AWS Lambda in Docker
Inspired by this awesome project