Using Puppeteer with AWS Lambda and Serverless

Kyle Higginson
2 min readJul 1, 2023



This article will talk you through how to use AWS Lambda to run automated UI scripts with Puppeteer and deployed using the Serverless framework.

Or just want to view it on Github? Click here!

  1. Install the two dependencies required for this: @sparticuz/chromium and puppeteer-core. Your package.json will end up like this:
"name": "aws-lambda-puppeteer-serverless",
"author": {
"name": "Kyle Higginson",
"email": ""
"scripts": {},
"dependencies": {
"@sparticuz/chromium": "^114.0.0",
"puppeteer-core": "^20.7.4"

2. Add your serverless.yml file, like so:

service: aws-lambda-puppeteer-serverless

name: aws
region: us-east-1
runtime: nodejs18.x

handler: run_puppeteer.handler
timeout: 20
- schedule: rate(10 minutes)

With this configuration, once deployed the lambda will run every 10 minutes.

3. Create a file named run_puppeteer.js at the root of your project, this will contain our handler for the lambda:

const chromium = require("@sparticuz/chromium")
const puppeteer = require("puppeteer-core")

function delay(time) {
return new Promise(function (resolve) {
setTimeout(resolve, time)

exports.handler = async (event) => {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,

const page = await browser.newPage()
await page.setViewport({
width: 1920,
height: 1080,

await page.goto("", {
waitUntil: "networkidle2",
timeout: 0,

await page.waitForSelector("#continueWithEmail")

await page.type("#emailInput", "")

await page.waitForSelector("#passwordInput", { visible: true })
await page.type("#passwordInput", "wrong_password")

await page.waitForSelector("#continueLoggingIn", { visible: true })

await page.waitForSelector("#monitorsList", { visible: true, timeout: 20000 })

const element = await page.waitForSelector("#monitorsList > li:first-of-type")

await delay(5000)

await browser.close()

return event

This script will not work as the user’s password is not correct. But you get the idea of how it will work. Orrr.. you could create an account at and get free AWS cost monitoring at the same time!

That’s it! You can now run puppeteer on AWS lambda :).