pwmetrics-lambda

1.0.0 • Public • Published

PWMetrics on AWS Lambda

This package allows you to run PWMetrics on AWS Lambda (Node 6.10.3), using a binary compiled specifically for that platform (from the Serverless Chrome project).

Usage

npm install --save pwmetrics-lambda

This package exports a function that wraps PWMetrics—see that package’s documentation for details on parameters and options. Like PWMetrics, it returns a Promise for the results of the the test(s).

Example Lambda function

This function accepts a URL to test and PWMetrics options from the Lambda event payload.

const lambdaPWMetrics = require('pwmetrics-lambda');
 
exports.handler = (event, context, callback) => {
    const { options, url } = event;
 
    lambdaPWMetrics(url, options).then(results => {
        // Do something with results.
        callback(null, results.runs);
    }).catch(callback);
};

Important considerations:

  • Increase the timeout to at least 15 seconds. Adjust as needed.

  • Increase the allotted memory to at least 768 MB. Adjust as needed. Resource- intensive pages may require considerably more memory.

  • Implement a catch method that calls the Lambda callback in case of a problem with the test.

  • The Chrome binary is quite large (~100 MB)—too big to upload directly to Lambda. You will need to sideload your function via S3. Most frameworks (e.g., Serverless, Claudia) support this either automatically or via options.

Testing locally

Because PWMetrics uses Lighthouse to launch Chrome, you can run it locally and Lighthouse should find and use a local copy of Chrome.

Package Sidebar

Install

npm i pwmetrics-lambda

Weekly Downloads

2

Version

1.0.0

License

ISC

Last publish

Collaborators

  • chriszarate