💥 Usefully docs and articles:
- Official Documentation Docker - Playwright Python
- New for AWS Lambda – Container Image Support
- Running End-to-End Tests with Playwright on AWS Lambda
It's easy to play with a Playwright, and I'm feeling more comfortable instead of using Selenium. Sometimes times need to deploy a solution completely serverless and here can do that with AWS Lambda and playwright. I searched on the web for this solution but did not have luck with the python approach (don't look too hard).
We want to build an AWS lambda based on docker images, this lambda will open a browser in headless mode and visit a website to extract it’s title and put in logs.
- nodejs v14.19.0
- npm
- Serverless Framework Core: 3.1.1
- Docker
- Python 3
- AWS Account (for test and deploy)
- aws-cli (for config de AWS profile)
-
Config your AWS profile and credentials,
aws configure
in the terminal. -
Set your env file before notting, Example
AWS_PROFILE=PROFILE AWS_REGION=eu-west-1 STAGE=dev
make install
All the app code is inside of app
folder, feel free to try your code and test.
Note: always the handler is the main function on
app/main.py
make build
make deploy stage=dev
This command deploy the serverless solution and create
- Cloudformation stack with all resources.
- S3 bucket with all the code or artifacts of the project.
- ECR repository to upload the docker image for the lambda.
- Lambda function.
make deploy stage=dev
$ ❯ make invoke stage=dev 4s aws-lambda-playwright 18:07:22
Running "serverless" from node_modules
null
--------------------------------------------------------------------
START
Start
Launch browser with args: ['--disable-dev-shm-usage', '--ipc=host', '--single-process']
Open new page
Go to url: https://playwright.dev
Page title: Fast and reliable end-to-end testing for modern web apps | Playwright
End
END Duration: 3290.65 ms Billed Duration: 3291 ms Memory Size: 1024 MB Max Memory Used: 203 MB