AWS Lambda Lighthouse Function
Allows running Lighthouse from AWS Lambda.
Setup
1. Creating Chromium Lambda Layer
First you'll need to create a layer that contains Chromium to be able to run Lighthouse with. For that we'll be using the Chrome AWS Lambda repo. In your terminal run:
git clone --depth=1 https://github.com/alixaxel/chrome-aws-lambda.git && \
cd chrome-aws-lambda && \
make chrome_aws_lambda.zip
To create a chrome_aws_lambda.zip
file.
You can also download this file from one of that repo's CI workflow runs.
2. Create New Layer
Log in to AWS and navigate to Lambda.
- In the left sidebar navigation go to Additional Resources > Layers
- Click the "Create Layer" button
- Enter a "Name" for this new layer, e.g. chromiumLayer
- Select "Upload a .zip file" and click the "Upload" button, select your
chrome_aws_lambda.zip
file - For "Compatible runtimes" select
Node.js 14.x
- Click "Create"
3. Create Function Assets
Back in the terminal on your computer run:
git clone git@github.com:ractoon/lighthouse-lambda.git
cd lighthouse-lambda
npm install
zip lighthouse-lambda.zip index.js node_modules
4. Create Lambda Function
- Navigate to AWS Lambda again and in the navigation sidebar go to "Functions"
- Click the "Create Function" button
- Select "Author from scratch" and enter a function name
- Select
Node.js 14.x
as the runtime - Click "Create function"
- After the function is created, in the "Code source" section select "Upload from" and choose ".zip file", select the
lighthouse-lambda.zip
file you created above - In the "Layers" section click "Add a layer"
- Click on "Custom layers"
- Select the layer you created above, and click "Add"
5. Lambda Resources
In order to run Chromium the lambda configuration will need to be updated with some additional memory, and an increased timeout.
- In the "Configuration" tab click on "General configuration", and click "Edit"
- Within the "General configuration" panel set the memory to
1600MB
and timeout to5 minutes
- Click "Save"
6. Testing Your Function
In the "Test" tab create a new test event with the body:
{
"url": "https://www.google.com"
}
Save your changes and then hit the "Test" button. It will run your function and should return "Execution result: succeeded" with the details containing the JSON result from lighthouse.
Configuration
The url
parameter is required to retrieve lighthouse results. You can also pass options
which accepts lighthouse flags.