October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

Create Website Screenshots with Python Selenium on AWS Lambda

A practical guide to packaging Selenium, a compatible browser, and WebDriver for AWS Lambda, with handler code, container deployment steps, readiness guidance, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture a website screenshot from Python on AWS Lambda, package Selenium, a compatible Chrome or Chromium browser, its matching WebDriver, and required system libraries in a Linux Lambda container image. The function must launch the browser with Lambda-compatible settings, wait for a page-specific readiness condition, save or return the PNG, and always close the browser.

This guide provides a starting implementation and deployment workflow. Browser packaging depends on the chosen base image, browser build, driver, and architecture, so validate the complete image in your target Lambda environment before relying on it in production.

What you need to package for Selenium screenshots

Selenium is the Python interface that controls a browser through WebDriver; it does not include the browser itself. Your Lambda image therefore needs all of the following:

  • The Python Selenium package and your handler code.
  • A Linux-compatible Chrome or Chromium binary.
  • A WebDriver compatible with that browser build.
  • The browser’s required shared libraries and fonts.
  • A writable location for browser profile and temporary files, commonly under /tmp.

Pin and test a compatible browser/driver pair rather than assuming that a package or third-party bundle will remain current. Browser releases and base-image updates can change compatibility.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall

Choose a Lambda packaging approach

Container image

A container image is a practical option when the browser binary and native libraries make the complete runtime difficult to package otherwise. AWS supports Python Lambda container images based on an AWS Python image, an AWS OS-only image, or a non-AWS base image. An AWS Python base image includes the runtime and Lambda-related components; if you use an OS-only or other base image, include a compatible Python runtime interface client.

Lambda container images must be Linux-based and target one architecture per function image. AWS sets the maximum uncompressed image size, including layers, at 10 GB. Python 3.12 and later AWS base images use Amazon Linux 2023 and microdnf (also available as dnf); some earlier runtimes use Amazon Linux 2 and yum. Check AWS’s current runtime tags and lifecycle dates before selecting a base image: Deploy Python Lambda functions with container images and Create a Lambda function using a container image.

Layer or other package

A layer or another packaging method may also be workable, but browser dependencies, image size, and native-library compatibility still need validation. The cited AWS container-image guidance does not establish that one approach is universally better for Selenium screenshots; choose based on the size and reproducibility of your browser stack and test the deployed artifact.

Rank #2
Dell Latitude 3190 11.6" HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
  • 1.1 GHz (boost up to 2.4GHz) Intel Celeron N5030 Quad-Core
  • 4GB DDR4 System Memory; 128GB Solid State Drive
  • 11.6" HD (1366 x 768) Multi-Touch Display
  • Combo headphone/microphone jack - Noble Wedge Lock slot - HDMI; 2 USB 3.1 Gen 1
  • Windows 11 Pro

Write a handler that waits, captures, and cleans up

The example below assumes your image already contains a browser and matching driver accessible to Selenium. It accepts a URL and optional viewport dimensions, writes a PNG to /tmp, and returns it as Base64 in a JSON response. That response method is suitable only when the screenshot fits your invocation’s response path and limits; for durable or larger outputs, upload the file to a storage destination you configure and return a reference instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The readiness check looks for a configurable CSS selector. Replace the default with an element that means the page is useful for your specific site. A successful navigation call alone does not prove that client-side rendering, images, or other content is visually complete.

import base64
import json
import os
import tempfile
from urllib.parse import urlparse

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


def lambda_handler(event, context):
    url = event.get("url")
    if not isinstance(url, str):
        return {"statusCode": 400, "body": "Provide a URL string."}

    parsed = urlparse(url)
    if parsed.scheme not in ("http", "https") or not parsed.netloc:
        return {"statusCode": 400, "body": "URL must be an absolute http or https URL."}

    width = int(event.get("width", 1280))
    height = int(event.get("height", 800))
    if not (1 <= width <= 4096 and 1 <= height <= 4096):
        return {"statusCode": 400, "body": "Viewport dimensions are out of range."}

    selector = event.get("ready_selector", "body")
    wait_seconds = float(event.get("wait_seconds", 15))
    if wait_seconds <= 0:
        return {"statusCode": 400, "body": "wait_seconds must be positive."}

    options = Options()
    options.add_argument("--headless")
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-dev-shm-usage")
    options.add_argument("--disable-gpu")
    options.add_argument("--window-size={},{}".format(width, height))
    options.add_argument("--user-data-dir=" + tempfile.mkdtemp(prefix="chrome-", dir="/tmp"))

    driver = None
    try:
        driver = webdriver.Chrome(options=options)
        driver.set_page_load_timeout(min(wait_seconds + 10, 60))
        driver.set_window_size(width, height)
        driver.get(url)
        WebDriverWait(driver, wait_seconds).until(
            EC.presence_of_element_located(("css selector", selector))
        )

        filename = "/tmp/capture.png"
        if not driver.save_screenshot(filename):
            raise OSError("WebDriver could not save the screenshot")
        with open(filename, "rb") as image_file:
            encoded = base64.b64encode(image_file.read()).decode("ascii")

        return {
            "statusCode": 200,
            "headers": {"content-type": "application/json"},
            "body": json.dumps({"image_base64": encoded, "format": "png"}),
        }
    except Exception as exc:
        print("Screenshot capture failed:", repr(exc))
        return {"statusCode": 502, "body": "Screenshot capture failed."}
    finally:
        if driver is not None:
            driver.quit()

Selenium’s save_screenshot(filename) saves the current browser window as a PNG and returns false if it cannot write the file. It also offers get_screenshot_as_png() for PNG bytes and a Base64 screenshot method. See the Python WebDriver API and Selenium getting started guide.

Rank #3
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
  • 256 GB SSD of storage.
  • Multitasking is easy with 16GB of RAM
  • Equipped with a blazing fast Core i5 2.00 GHz processor.

The sample’s checks are intentionally basic. For a public endpoint, avoid allowing arbitrary destinations without considering access to internal services, and bound navigation, wait, and output resources. Add authentication, destination controls, logging, and a storage integration appropriate to your application.

Build and deploy the Lambda image

  1. Create the image. Start from an AWS Python base image for the runtime you selected. Install Selenium and the Linux libraries your chosen browser needs, and copy in a browser and compatible driver. Put your function code under the Lambda task root and configure the image command to your handler.
  2. Match the architecture. Build for the architecture configured for the function. AWS’s example uses docker buildx build --platform linux/amd64 --provenance=false; use linux/arm64 when targeting arm64 and ensure the browser and driver support it.
  3. Test the built artifact. Invoke it locally using AWS’s runtime interface emulator, then test in Lambda-like conditions. Confirm browser startup, writable paths, fonts and libraries, screenshot dimensions, wait behavior, and execution timeout.
  4. Push and deploy. Push the image to Amazon ECR and configure the Lambda function to use it. Publishing a new image to ECR does not, by itself, update the function code: rebuild and update the function when browser, driver, dependencies, or handler code changes. Follow AWS’s container image deployment workflow.

Choose capture readiness and output deliberately

Readiness

Use a selector or condition that reflects the content you need, such as a report heading or product card. A generic body check only confirms that the document body exists. If content renders asynchronously, wait for the relevant element or another explicit condition and keep that wait bounded. Selenium also exposes page-load and script timeout controls; set them to fit within the Lambda execution timeout rather than letting browser work consume the entire invocation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Viewport and full-page behavior

save_screenshot captures the current browser window. Setting width and height controls the viewport, but does not turn the capture into a full-page screenshot. If you require an entire long page, implement and verify a separate full-page strategy for the browser build you package instead of promising that a normal window capture includes content below the viewport.

Rank #4
15.6 Inch Laptop Computer, N4020, 4GB DDR4 RAM, 128GB eMMC,with Windows 11
  • EFFORTLESS EVERYDAY PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 Home system, delivering reliable, low-power efficiency for daily tasks like document editing, email, online classes, and web browsing
  • 15.6-INCH FULL HD DISPLAY: Enjoy immersive visuals on the 15.6" FHD (1920x1080) anti-glare screen with micro-edge bezels. Delivers clear details and comfortable viewing for long study sessions, working on spreadsheets, and video playback
  • RESPONSIVE MULTITASKING & STORAGE: Built with 4GB LPDDR4 RAM and 128GB eMMC storage for smooth daily essential use. Expand your storage by up to 1TB via the integrated TF card slot to easily store movies, photos, and working files
  • ADVANCED CONNECTIVITY: Outfitted with 2x Full-Featured Type-C ports for data transfer, fast charging, and dual-monitor output, alongside 2x USB 3.2 Gen1 ports and a 3.5mm audio jack for complete peripheral compatibility
  • LIGHTWEIGHT & SILENT OPERATION: Slim and portable for effortless travel or commuting. Features a 1MP HD webcam for remote meetings, 38Wh battery with 45W Type-C fast charging, and a fanless silent design for peaceful work environments.

Output destination

  • Return bytes: capture with get_screenshot_as_png() or read a temporary PNG and encode it for a response when the output is suitably small.
  • Persist a file: write to a configured storage service and return a key or URL when the image must outlive the invocation or the response path is unsuitable.
  • Temporary files: use writable temporary storage for the browser profile and intermediate image, and do not assume temporary files are a durable destination.

Performance, reliability, and cost considerations

Browser startup, page behavior, image size, and dependency loading determine how an invocation performs. No fixed latency or cold-start figure applies across browser builds and target sites. Keep the browser and driver versions pinned, use bounded timeouts, and test the exact image after updates. A browser failure, slow navigation, or a page that never meets its readiness condition should produce a controlled error rather than leave the invocation waiting indefinitely.

Set the Lambda memory and execution timeout to values validated under your workload; this guide does not provide benchmark-derived settings. Include the time for browser startup, page navigation, readiness, and output handling in your timeout budget. For recurring browser-based synthetic monitoring rather than a custom screenshot handler, AWS CloudWatch Synthetics canaries provide programmatic browser access through Playwright, Puppeteer, or Selenium WebDriver: Synthetic monitoring (canaries).

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

  • Chrome or driver cannot start: confirm both binaries are present, executable, compatible with one another, and built for the function’s Linux architecture. Check missing shared libraries and the browser’s startup logs.
  • Browser exits or cannot create a profile: direct profile and temporary files to writable storage such as /tmp; verify that the configured path exists and is writable.
  • Navigation times out: check the target’s response and redirects, lower the navigation timeout to fit the Lambda budget, and wait separately for a meaningful page condition. Avoid treating navigation completion as proof that all visual content is ready.
  • Screenshot is blank or incomplete: choose a stronger readiness condition, check whether the site requires authentication or client-side rendering, and verify viewport and page state before capture.
  • Screenshot file is missing: check the boolean result from save_screenshot, catch file I/O errors, and read or upload the file before the handler returns.
  • Deployment still runs old code: updating ECR alone does not update the Lambda function’s deployed image reference. Update the function after publishing the new image.
  • Image build or deployment rejects the artifact: confirm it is Linux-based, built for one architecture matching the function, and within the 10 GB uncompressed image limit.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One GET request can return a PNG, JPEG, WebP, or PDF; cookie banners, newsletter popups, and chat widgets are removed before capture. Bot checks, blank pages, and failed loads are never billed, and responses identify the page verdict and billing status. Its MCP server lets AI agents use screenshot tools, and it supports 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For API details and parameters, see the ScreenshotNeo documentation.

Best Value
Sale
15.6 Inch Win 11 Laptop Computer, N4020, 4GB DDR4 RAM, 128GB Storage
  • WINDOWS 11 | STABLE PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 system, this laptop delivers stable performance for everyday computing tasks. It supports web browsing, online learning, document editing, email communication, and basic office work with optimized power efficiency, providing a practical and reliable experience for essential daily use for daily use.
  • 15.6” FHD IPS DISPLAY: Features a 15.6-inch Full HD IPS display with narrow bezels, offering wider viewing angles and clearer image details compared to standard panels. The improved screen-to-body ratio enhances visual experience for study, reading, document work, and video playback, making it suitable for both productivity and entertainment use.
  • 4GB DDR4 + 128GB eMMC STORAGE: Equipped with 4GB DDR4 memory and 128GB eMMC storage for everyday basics such as browsing, documents, email, and online learning platforms. The built-in TF card slot supports storage expansion up to 1TB, giving you more flexibility for files, photos, videos, and daily documents. TF card not included.
  • CONNECTIVITY & PORTS: Includes 1× TF card slot, 2× USB 3.2 Gen1 ports, and 2× full-featured Type-C ports (USB 3.2 Gen1). The Type-C ports support data transfer, charging, and video output, enabling flexible connection with external devices such as monitors, storage, and peripherals for daily work and study use.
  • LIGHTWEIGHT DESIGN | ONLINE COMMUNICATION: Designed with a slim, portable profile, this laptop is easy to carry for school, commuting, and travel. A built-in 1MP front camera supports online classes, video meetings, remote communication, and everyday conferencing. The 3300mAh battery works with the low-power system design to support practical daily use, while thermal optimization helps maintain quieter operation during extended tasks.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Sign up for ScreenshotNeo free to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Does Selenium’s regular screenshot method capture the whole webpage?

No. It captures the current browser window; a full-page result requires a separate implementation that you validate with your packaged browser.

Can AWS CloudWatch Synthetics run Selenium?

AWS documents canary runtimes with browser automation through Selenium WebDriver as well as Playwright and Puppeteer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
HP 14' HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
HP 14" HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
14" diagonal, 1366x768 resolution, HD BrightView LED, Glossy NON-TOUCH Display
$249.99
Bestseller No. 2
Dell Latitude 3190 11.6' HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
Dell Latitude 3190 11.6" HD 2-in-1 Touchscreen Laptop Intel N5030 1.1Ghz 4GB Ram 128GB SSD Windows 11 Professional (Renewed)
1.1 GHz (boost up to 2.4GHz) Intel Celeron N5030 Quad-Core; 4GB DDR4 System Memory; 128GB Solid State Drive
$179.99
Bestseller No. 3
Dell Latitude 5420 14' FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
256 GB SSD of storage.; Multitasking is easy with 16GB of RAM; Equipped with a blazing fast Core i5 2.00 GHz processor.
$304.00

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.