Skip to content

A Docker image that creates a containerized AWS Lambda runtime with Playwright installed as a Python library with all dependencies. Only headless Chromium included. Can be tested locally.

Notifications You must be signed in to change notification settings

olga-terekhova/lambda-python-playwright-chromium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lambda-python-playwright-chromium

A Docker image that creates a containerized AWS Lambda runtime with Playwright installed as a Python library with all dependencies.
Only headless Chromium included, so the image size is only 2GB (as compared to the microsoft-playwright image at 3.5GB).
All user logic should be contained in a separate python script uploaded to S3. It will be executed by the default hanlder of this lambda function.
Can be tested locally (the same image could be run locally or on AWS).

Project structure:

lambda-python-playwright-chromium/
├─ Dockerfile (instructions for building the image in Docker)
├─ README.md
├─ src/
│ ├─ aws-lambda-rie (emulator needed for local testing, source )
│ ├─ lambda_function.py (lambda function code)
│ ├─ requirements.txt (lists of python libraries to install, playwright and awslambdaric are required for this functionality)
│ ├─ start.sh (a switch that determines the environment (local or cloud) and uses an emulator if needed)
├─ test/ │ ├─ event.json (a payload for testing) │ ├─ event_example.json (a reference template for event.json) │ ├─ user_function_example.py (an example of user submitted python file, should be uploaded to S3)

What's useful here compared to other base images and walkthroughs

The image is build on a base Ubuntu image.
Python, Python libraries, and Playwright dependencies are installed on top of it.
The resulting size of the image is 2 GB.

  1. It is smaller compared to the official Microsoft Playwright image for Python at 3.51 GB, as only chromium headless is included.
  2. It is smaller compared to the official Python on Debian distribution at 3.47 GB, as this image installs Python on top of a vanilla Ubuntu image.

This image has a correct start.sh file which build Lambda Runtime emulator into the image and allows the same image be run locally and in the cloud.
The AWS documentation example omits passing the parameter into the script, so the AWS runtime emulator doesn't see the lambda module and function handler passed in CMD.

All user logic is removed into a separate python file, so this container doesn't have to be rebuild every time the end function changes. This container acts a stable runtime which provides python execution capabilities with additional system libraries needed for the playwright module.

About

A Docker image that creates a containerized AWS Lambda runtime with Playwright installed as a Python library with all dependencies. Only headless Chromium included. Can be tested locally.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published