Skip to content

saqemlas/sls-headless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Headless Browsing with Lambda

There are some considerations when working with Puppeteer on AWS Lambda...

  • Lambda limits deployment package sizes up to ~50MB and docker images up to ~10GB.
  • Using a docker image allows for control over which browser is used, ie google chrome over chromium.
  • The docker image can take considerable time to build and upload when installing puppeteer (+ system dependencies) and google-chrome or chromium (+ system dependencies), slowing down development and deployment time. A base image should probably be used due to the infrequency of these libraries being updated.
  • Chromium currently does not provide arm64 binaries for Linux. (Issue#7740)
  • Puppeteer is unreliable and unstable as it is, but proves extra difficult when confguring for multi-arch.

As per Puppeteer recommendations for Lambda

  • @sparticuz/chromium
    • A vendor and framework agnostic library that supports modern versions of chromium
    • Can be used with newer versions of puppeteer.
    • Does not support arm64
    • Using this library with puppeteer-core ensures the lambda is the smallest size out of all set ups, reducing cold-start times.
    • Locally puppeteer is used under devDepencencies and uses Google Chrome on the laptop (Mac M1)

Info

This handles deployment for a public http api with integrated lambda, the lambda has puppeteer and chromium installed for headless browsing. On a GET http request, a response of a screenshot of google homepage is returned.

Usage

Credentials:

export AWS_PROFILE=<profile_name>

Install Dependencies:

yarn run install

Local:

yarn run invoke

Deploy:

yarn run deploy

Remove:

yarn run remove