lambda-chrome-puptr has everything to deploy and run Puppeteer with Headless Chrome in AWS Lambda using chrome-aws-lambda as chrome-aws-lambda-layer.
There are many examples that use "chrome for lambda" as packaged binary into "lambda package" or use "chrome for lambda" binary from AWS S3 bucket. And many might have earlier used puppeteer-lambda-starter-kit where someone has to ensure to maintain compatibility across all used frameworks/packages and binaries to make it work.
Similarly, I also frequently faced challanges to maintain compatible versions of chrome for lambda, Puppeteer, Node.js and lambda runtime together. Thanks to shelfio to publish solid lambda layer containing chrome for lambda and Puppeteer and keeping it up-to-date and compatible with latest versions. And this lambda layer inspired to develop read-to-use and extensible lambda-chrome-puptr.
High level steps:
- Clone this repo
- Run
npm install
- Ensure to modify AWS S3 bucket name for
scrnshotsBucket
to your bucket name inserverless.yml
- Verify AWS region in
serverless.yml
where you want deploy. And ensure value oflayers
i.e. "arn:aws:lambda:us-east-1
:764866452798:layer:chrome-aws-lambda:10" matches with your AWS region as well - Run
sls deploy --aws-profile
your-aws-profile-name - This should have deployed AWS Lambda and have attached Lambda Layer with it
- Now to test lambda, enter
{ "url": "https://pptr.dev/" }
as lambda input whereurl
contains website-name of which the screenshot to be captured and uploaded to S3 - On succsessful lambda run, it returns publicly accessible screeshot-url
- Please Note: This code, for demostration purpose, makes AWS S3 bucket publicly accessible. Please modify it as per your requirements.