![](/img/trans.png)
[英]How to use chrome-aws-lambda module with AWS lambda functions?
[英]How to use chrome-aws-lambda on a AWS lambda function created with Amplify
I'm trying to create this lambda function in AWS using Amplify however when I try to launch the chromium the lambda function does not return any value and the function end up timing up:
"errorMessage": "2020-12-09T02:56:56.210Z 57402f8e-9fb2-4341-837d-bdf2ee6e9262 Task timed out after 25.57 seconds"
我按照@James Shapiro 的建议添加了图层,现在我得到了 ZE6B391A8D2C4D45902A23A8B65857 返回对于铬,但它仍然没有启动它:
这是我的 function:
const chromium = require('chrome-aws-lambda');
exports.handler = async (event, context) => {
const pageToScreenshot = "https://www.google.com"
console.log('page:', pageToScreenshot);
if (!pageToScreenshot) return {
statusCode: 400,
body: JSON.stringify({ message: 'Page URL not defined' })
}
console.log('launch:');
console.log('chromium.args:', chromium.args);
console.log('chromium.defaultViewport:', chromium.defaultViewport);
console.log('chromium.headless:', chromium.headless);
const executablePath = await chromium.executablePath;
const browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath,
headless: chromium.headless,
});
console.log('page:');
const page = await browser.newPage();
console.log('goto:');
await page.goto(pageToScreenshot, { waitUntil: 'networkidle2' });
console.log('screenshot:');
const screenshot = await page.screenshot({ encoding: 'binary' });
console.log('close:');
await browser.close();
console.log('response:');
return {
statusCode: 200,
body: JSON.stringify({
message: `Complete screenshot of ${pageToScreenshot}`,
buffer: screenshot
})
}
}
这是依赖项:
{
"name": "snapshot31baa866",
"version": "2.0.0",
"description": "Lambda function generated by Amplify",
"main": "index.js",
"license": "Apache-2.0",
"dependencies": {
"chrome-aws-lambda": "^5.5.0",
"puppeteer-core": "^5.5.0"
}
}
日志:
START RequestId: 6dc39c75-0577-492d-b305-6d5c95778eea Version: $LATEST 2020-12-09T04:56:34.141Z 6dc39c75-0577-492d-b305-6d5c95778eea INFO page: https://www.google.com 2020-12 -09T04:56:34.141Z 6dc39c75-0577-492d-b305-6d5c95778eea 信息发布:2020-12-09T04:56:34.143Z 6dc39c75-0577-492d-b305-6d5c95778eea 信息 chromium-policy.args: [ =用户手势要求',
'--禁用后台网络',
'--disable-background-timer-throttling',
'--disable-backgrounding-occluded-windows', '--disable-breakpad',
'--disable-client-side-phishing-detection',
'--disable-component-update', '--disable-default-apps',
'--disable-dev-shm-usage', '--disable-domain-reliability',
'--禁用扩展',
'--disable-features=AudioServiceOutOfProcess',
'--disable-hang-monitor', '--disable-ipc-flooding-protection',
'--禁用通知',
'--disable-offer-store-unmasked-wallet-cards',
'--disable-popup-blocking', '--disable-print-preview',
'--disable-prompt-on-repost', '--disable-renderer-backgrounding',
'--disable-setuid-sandbox', '--disable-speech-api',
'--disable-sync', '--disk-cache-size=33554432',
'--hide-scrollbars', '--ignore-gpu-blacklist',
'--metrics-recording-only', '--mute-audio',
'--no-default-browser-check', '--no-first-run', '--no-pings',
'--no-sandbox', '--no-zygote', '--password-store=basic',
'--use-gl=swiftshader'、'--use-mock-keychain'、'--single-process'] 2020-12-09T04:56:34.168Z 6dc39c75-0577-492d-b305-6d5c95778eea 信息铬。 defaultViewport: { deviceScaleFactor: 1, hasTouch: false, height: 1080,
isLandscape: true, isMobile: false, width: 1920 } 2020-12-09T04:56:34.168Z 6dc39c75-0577-492d-b305-6d5c95778eea INFO chromium.headless: true 2020-12-09T04:56:57.868Z 6dc39c75-05 -492d-b305-6d5c95778eea INFO chromium.executablePath: /tmp/chromium END RequestId: 6dc39c75-0577-492d-b305-6d5c95778eea REPORT RequestId: 6dc39c75-0577-492d-b305-6d5c95778eea Duration: 25009.76 ms Billed Duration: 25000 ms Memory Size :最大 128 MB Memory 已使用:128 MB 初始化持续时间:168.98 ms 2020-12-09T04:56:59.150Z 6dc39c75-0577-492d-b305-6d5c95778eea 任务超时秒后。
您是否尝试过安装chrome-aws-lambda
层,然后将其添加到 function 中? 请参阅“AWS Lambda 层”部分中的说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.