lighthouse-layer
lighthouse-layer copied to clipboard
Lambda Size Limit Reached
I'm new to lambda and trying to deploy and run lighthouse on AWS Lambda but whenever I try to run yarn deploy
the package I get the below error:
An error occurred: LambdaFunction - Unzipped size must be smaller than 262144000 bytes (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: xxxx-xxxx-xxxx-xxxx)
This is due to the uncompressed chromium binary, so I then tried using the chrome-aws-lambda
module instead of the chrome-launcher
with the below lambda function and environment variables:
index.js:
const chromium = require('chrome-aws-lambda');
const lighthouse = require('lighthouse');
const log = require('lighthouse-logger');
exports.handler = async (event, context, callback) => {
let result = null;
let browser = null;
try {
browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
let page = await browser.newPage();
await page.goto(event.url || 'https://google.com');
result = await page.title();
const options = {
port: browser.port,
logLevel: 'info',
};
log.setLevel(options.logLevel);
const results = await lighthouse('https://google.com', options);
} catch (error) {
return callback(error);
} finally {
if (browser !== null) {
await browser.close();
}
}
return callback(null, result);
};
Environment Variables:
But I'm now getting this error:
{ "errorType": "Error", "errorMessage": "connect ECONNREFUSED 127.0.0.1:9222", "trace": [ "Error: connect ECONNREFUSED 127.0.0.1:9222", " at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)" ] }
So my question is:
- How can I run the original
chrome-launcher
lambda without running into the lambda size limitation issue? - How can I use the
chrome-aws-lambda
to get the lighthouse results?
To Note that if I run the same code with chrome-aws-lambda
but without const results = await lighthouse('https://google.com', options);
, I get the expected result:
"Google"
So maybe I'm doing something wrong with the deployment of the layer or there's an issue with lighthouse
using chrome-aws-lambda
Having same problem here.
Same error message.
I also ran into this Lambda size limit issue and might have a possible solution for:
- How can I run the original chrome-launcher lambda without running into the lambda size limitation issue?
I was able to remove some additional files that were not necessary located in the node_modules/chrome-aws-lambda/bin
directory. Since we are already copying them with the node decompress-binary.js
script.
"name": "lighthouse-layer-nodejs",
"private": true,
"version": "0.0.1",
"description": "lighthouse layer nodejs",
"engines": {
"node": ">= v12.18.0"
},
"scripts": {
"postinstall": "node decompress-binary.js && rm -rf ./node_modules/chrome-aws-lambda/bin"
},
"author": "Erez Rokah",
"license": "MIT",
"homepage": "https://github.com/adieuadieu/erezrokah/lighthouse-runner/layers/lighthouse/nodejs",
"dependencies": {
"axios": "^0.19.2",
"chrome-aws-lambda": "^7.0.0",
"chrome-launcher": "^0.13.0",
"google-spreadsheet": "^3.0.13",
"lighthouse": "^7.0.0",
"lighthouse-logger": "^1.2.0",
"readline": "^1.3.0"
}
}