3.1.1 • Published 6 years ago

lighthouse-lambda v3.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

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 3.x will use lighthouse 3.x.

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

Installation

$ npm install lighthouse-lambda --save

Lambda function

// index.js

const createLighthouse = require('lighthouse-lambda')

exports.handler = function (event, context, callback) {
  Promise.resolve()
    .then(() => createLighthouse('https://example.com', { logLevel: 'info' }))
    .then(({ chrome, start }) => {
      return start()
        .then((results) => {
          // Do something with `results`
          return chrome.kill().then(() => callback(null))
        })
        .catch((error) => {
          // Handle errors when running Lighthouse
          return chrome.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:nodejs8.10 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-nodejs8.10 bash -c "rm -rf node_modules && npm install"

$ docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs8.10 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:

  • chrome: an instance of chromeLauncher.launch(), remember to call chrome.kill() in the end.
  • log: an instance of lighthouse-logger (only if you set options.logLevel).
  • start(): a function to start the scan which returns a Promise of Lighthouse results.

Credits

lighthouse-lambda uses the Headless Chrome binary (stable version) from @serverless-chrome/lambda.

License

MIT

3.1.1

6 years ago

2.1.0

6 years ago

3.1.0

6 years ago

2.0.5

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.4

6 years ago

3.0.0-rc.3

6 years ago

2.0.3

6 years ago

3.0.0-rc.2

6 years ago

2.0.2

6 years ago

3.0.0-rc.1

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago