Skip to content

Repository files navigation

joytocode/lighthouse-lambda

Run Google Chrome Lighthouse on AWS Lambda.

Versions

Since version 2.x, lighthouse-lambda has the same major version of lighthouse. For example, lighthouse-lambda 5.x will use lighthouse 5.x.

This README is for version 5.x. To see older versions, visit:

Installation

$ npm install lighthouse-lambda --save

Lambda function

// index.jsconstcreateLighthouse=require('lighthouse-lambda')exports.handler=function(event,context,callback){Promise.resolve().then(()=>createLighthouse('https://example.com',{logLevel: 'info'})).then(({ chrome, log, results })=>{// Do something with `results`returnchrome.kill().then(()=>callback(null))}).catch((error)=>{// Handle errors when running Lighthousereturnchrome.kill().then(()=>callback(error))})// Handle other errors.catch(callback)}

Testing locally

You can use docker-lambda to test your Lambda function locally.

$ docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs12.x index.handler

Deployment

You can use docker-lambda to install dependencies and pack your Lambda function.

$ docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs12.x bash -c "rm -rf node_modules && npm install"
$ docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs12.x bash -c "rm -f *.zip && zip lambda.zip -r node_modules index.js package.json"
  • The file will be big (at least 75MB), so you need to upload it to S3 then deploy to Lambda from S3.
  • You should allocate at least 512 MB memory and 15 seconds timeout to the function.

API

createLighthouse(url, [options], [config])

Same parameters as Using Lighthouse programmatically.

Returns a Promise of an Object with the following fields:

Credits

License

MIT

About

🆗 Run Google Chrome Lighthouse on AWS Lambda.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages