Skip to content

enrialonso/aws-lambda-playwright-python

Repository files navigation

AWS lambda with playwright on python


💥 Usefully docs and articles:

Why ❓

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).

⚽ Our goal

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.

Dependencies

  • 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)

🔤 Requirements configurations

  • 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
    

Install dependencies

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

Build a docker image

make build

Deploy

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.

Test the lambda

make deploy stage=dev

🍔 Output

$ ❯ 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published