StarterKitforrunningHeadless-ChromebyPuppeteeronAWSLambda.
ItcanusealoneandalsosupportedServerlessFramework.
DownloadUsealoneThisissimpleanddon'tneedIAMrolebutyouhavetodeploypackagebyyourself.Don'tworry,evenifyouwillbecometouseServerlessinthefuture,whatyoushoulddoformigrationislittle.
$gitclone-ostarter-kithttps://github.com/sambaiz/puppeteer-lambda-starter-kit.gityour_project_nameUsewithServerlessFrameworkServerlessFrameworkcanmanagesettingswithCloudFormationanddeploy.
$serverlessinstall--urlhttps://github.com/sambaiz/puppeteer-lambda-starter-kit--nameyour_project_nameRunonlocalByexecutingSLOWMO_MS=250npmrunlocal,youcanchecktheoperationwhileactuallyviewingthechrome(non-headless,slowmo).
Packaging&DeployLambda'smemoryneedstobesettoatleast384MB,butthemorememory,thebettertheperformanceofanyoperations.
512MB->goto(youtube):6.481s1536MB->goto(youtube):2.154schromeinpackage(recommended)Ifyouusealone,runnpmrunpackage,anddeploythepackage.zip.
IfyouusewithServerless,runserverlessdeploy(thisrunsnpmrunpackagewhenpackaging).
chromeNOTinpackageDuetothelargesizeofChrome,itmayexceedtheLambdapackagesizelimit(50MB)dependingontheothermoduletoinclude.Inthatcase,putChromeinS3anddownloaditatcontainerstartupsostartuptimewillbelonger.
Runnpmrunpackage-nochrome,deploythepackage.zip,andsetfollowingenvvaliablesonLambda.
CHROME_BUCKET(required):S3bucketwhereChromeisputCHROME_KEY(optional):S3key.default:headless_shell.tar.gzBuildHeadless-Chrome(optional)ThiskitincludesChromebuiltbymyselfbecauseofficialbuildChromeinstalledbyPuppeteerhasproblemsaboutrunningonLambda(missingsharedlibraryetc.).
Ifyouwanttouselatestchrome,runchrome/buildChrome.shonEC2havingatleast16GBmemoryand30GBvolume.Seealsoserverless-chrome.Onceyoubuildit,linktoheadless_shell.tar.gzinchromedir.
ArticleLambda上でPuppeteer/HeadlessChromeを動かすStarterKitを作った-sambaiz-net
评论