To capture a website with Selenium in an AWS Lambda function, package Python, a compatible Chrome or Chromium binary, and its matching WebDriver in a Linux container image; launch the browser in headless mode; wait for the page condition you need; then save or return the PNG and always close the browser. The example below shows the function flow, but the exact browser build, driver pairing, libraries, and startup flags must be validated for your Lambda architecture and image.
What you need to package and decide
Selenium controls a browser through WebDriver; installing the Python Selenium package alone does not provide a browser. Your function image must contain a browser binary and a compatible driver, as well as any native libraries that browser build needs. Pin and test the browser and driver as a pair rather than assuming that a browser package or third-party bundle remains compatible.
A container image is a practical option when browser binaries and native dependencies make the deployment package awkward. AWS documents three base-image routes: an AWS Python base image, an AWS OS-only image, or a non-AWS image. The AWS Python base image includes the runtime and Lambda-related components; OS-only and other base images require a compatible Python runtime interface client. The exact trade-offs against Lambda layers depend on the browser build and dependency set, so validate the packaging route you choose.
- Choose the Lambda architecture first, then build the image for that architecture. Lambda container images must be Linux-based and target one architecture per function image.
- Choose viewport width and height, whether you need the current viewport or a separately implemented full-page capture, and the page-specific readiness condition.
- Decide whether the function returns PNG bytes to its caller or persists the image, for example to object storage. The example returns bytes through a Base64-encoded JSON response; adjust the integration if your caller expects a binary response.
- Bound navigation and wait durations so the browser work fits the function’s execution timeout.
AWS sets the maximum uncompressed Lambda container image size at 10 GB, including layers. Python 3.12 and later AWS base images use Amazon Linux 2023 and microdnf (also symlinked as dnf); older listed runtimes may use Amazon Linux 2 and yum. Check AWS’s current runtime tags and deprecation dates before selecting a base image, since those change over time. AWS Python container-image guide · Lambda container image requirements
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Example Lambda handler
This example illustrates the request flow and cleanup, not a tested browser installation recipe. Set CHROME_BIN and CHROMEDRIVER to the paths used by your image, and adapt Chrome options to the browser build you package. It accepts an event containing url, optionally wait_for_css, and returns a Base64 PNG. Restrict permitted target URLs in a real service rather than exposing an unrestricted URL-fetching function.
import base64
import os
from urllib.parse import urlparse
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
def lambda_handler(event, context):
url = event.get("url")
if not isinstance(url, str):
raise ValueError("event.url must be a URL string")
parsed = urlparse(url)
if parsed.scheme not in ("http", "https") or not parsed.netloc:
raise ValueError("event.url must be an absolute http or https URL")
width = int(event.get("width", 1365))
height = int(event.get("height", 900))
if width < 1 or height < 1:
raise ValueError("width and height must be positive integers")
options = Options()
options.binary_location = os.environ.get("CHROME_BIN", "/opt/chrome/chrome")
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--window-size={},{}".format(width, height))
options.add_argument("--user-data-dir=/tmp/chrome-profile")
service = Service(os.environ.get("CHROMEDRIVER", "/opt/chromedriver"))
driver = None
try:
driver = webdriver.Chrome(service=service, options=options)
driver.set_page_load_timeout(25)
driver.set_script_timeout(10)
driver.get(url)
selector = event.get("wait_for_css")
if selector:
WebDriverWait(driver, 10).until(
lambda browser: browser.find_element(By.CSS_SELECTOR, selector)
)
png = driver.get_screenshot_as_png()
return {
"statusCode": 200,
"headers": {"content-type": "application/json"},
"body": base64.b64encode(png).decode("ascii"),
"isBase64Encoded": True,
}
finally:
if driver is not None:
driver.quit()
Use a site-specific selector or another meaningful condition where a page’s useful content appears after initial navigation. A selector only establishes that the matched element exists; if the page fills it asynchronously, wait for the needed state or content. Selenium’s get_screenshot_as_png() returns PNG bytes. If writing to disk instead, save_screenshot(filename) saves the current window as PNG and returns false on an I/O error, so check its return value. Selenium Python WebDriver API · Selenium getting started
The returned Base64 payload can be large, and the consuming integration must handle the chosen response format. For larger outputs or asynchronous workflows, persist the image to a destination such as object storage and return a reference instead of embedding the bytes. Give the function only the permissions it needs for that destination.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Build and deploy the container image
- Create a Dockerfile from an AWS Python base image. Install Python dependencies, add your selected browser and matching driver, and copy the handler into the task root. The names and installation commands for browser packages vary by base image and release; verify required shared libraries and executable paths against the image you actually build.
- Set the handler command. For a handler in
app.pynamedlambda_handler, configure the image command asapp.lambda_handler. AWS Python base images supply the Lambda runtime components; if you use an OS-only or non-AWS base, include the compatible runtime interface client. - Build for the function architecture. AWS’s guide demonstrates
docker buildx build --platform linux/amd64 --provenance=false; uselinux/arm64when that is the architecture selected for the function. Do not build a multi-architecture image for one Lambda function. - Exercise the built image before publishing. AWS documents local invocation with the Runtime Interface Emulator. Test browser startup, navigation, readiness waits, screenshot dimensions, output handling, and cleanup using the exact image. A successful Python import is not proof that Chrome can start in the Lambda runtime.
- Push to ECR and deploy the image. Follow AWS’s ECR workflow to push the image and create or update the Lambda function to use it. Publishing a new image to ECR alone does not update the deployed function; rebuild and update the function code when the browser, driver, dependencies, or handler changes.
See AWS’s current Python container-image instructions for the Dockerfile conventions, local emulator, and ECR workflow.
Free tools Windows power users keep installed
One-click scans. No signup required.
Capture readiness, viewport, and output deliberately
Wait for the right page state
driver.get() completes according to the browser’s navigation behavior, not a guarantee that every visible component, image, or client-rendered result is ready. Wait for a page-specific selector, a known state, or another condition that reflects the content your screenshot should contain. Keep navigation, script, and explicit waits within the Lambda execution budget; long waits can consume the invocation even when the page is stalled.
Know what the screenshot includes
Selenium’s ordinary window screenshot captures the current browser window. Set the viewport before capture when dimensions matter. Do not describe this as a full-page screenshot: full-page capture requires additional implementation and validation for the browser and page in use.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Choose a destination and handle failures
For a synchronous caller, return the bytes in the response format expected by that integration. For an image that may exceed practical response limits or needs to outlive the invocation, write it to persistent storage and return a location or identifier. Treat a false return from save_screenshot(), navigation timeouts, driver startup errors, and storage failures as failures rather than reporting a successful capture. The finally block ensures the driver is quit after success or an exception.
Troubleshoot common failures
- Chrome or WebDriver will not start: Confirm the browser and driver executables exist at the configured paths and are executable. Check that their versions are compatible, that all required native libraries are present, and that the image architecture matches the function architecture.
- Browser exits or cannot write its profile: Use a writable temporary path for the profile and other runtime files. Lambda-compatible startup flags can vary across browser builds; test them in the exact container rather than copying flags without validation.
- The image builds but Lambda rejects it: Confirm it is Linux-based, targets one architecture, stays within the 10 GB uncompressed limit, and follows the selected base image’s runtime requirements. For OS-only or non-AWS images, verify the runtime interface client is included.
- The screenshot is blank or misses content: Replace an arbitrary short sleep with a meaningful readiness condition, then inspect whether the selector represents loaded content rather than merely an empty container. Check the requested viewport and whether the site requires additional time or interaction.
- Navigation times out: Set a bounded page-load timeout and an explicit Lambda timeout budget. Decide whether the workload should fail, retry through a controlled mechanism, or capture only after a site-specific condition; do not leave an unbounded wait.
- The caller cannot display the returned PNG: Ensure the integration recognizes the response as binary/Base64 data, or persist the PNG and return a reference instead. Verify the function’s response path against the caller’s expected format.
- A new image does not change the running function: Update the function code to the new image after pushing it to ECR. An ECR push by itself does not switch the deployed function.
Performance, reliability, and security considerations
Browser startup, site behavior, image size, and cold starts vary with the browser build and workload; no fixed screenshot latency or image-size estimate applies here. Measure the exact container and target sites under the timeout and memory configuration you plan to use. Pin browser, driver, and Python dependency versions, and rebuild and retest when updating them. Leave time for browser shutdown and output persistence rather than allocating the entire invocation to navigation.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
If callers can supply URLs, constrain the destinations your function is allowed to fetch and bound execution and resource use. A screenshot endpoint that fetches arbitrary URLs can be abused to make requests to destinations the caller should not control; design destination validation and network access intentionally.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
For recurring synthetic monitoring rather than a custom screenshot endpoint, AWS CloudWatch Synthetics canaries offer browser automation through Playwright, Puppeteer, or Selenium WebDriver. This is a managed monitoring option, not necessarily a drop-in replacement for a function designed around your own inputs and output flow. AWS Synthetic monitoring (canaries)
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
ScreenshotNeo provides a website screenshot API. One GET request returns a screenshot; this cURL example saves a WebP image. See the ScreenshotNeo API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots, and every feature is available on every plan. Learn about ScreenshotNeo.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Sign up free for 1,000 screenshots a month with no card.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Frequently Asked Questions
Does Selenium’s ordinary screenshot method capture the full webpage?
No. The ordinary window screenshot captures the current browser window; full-page capture needs additional implementation.
Can this example accept any URL safely?
It validates URL syntax only. A deployed service should restrict permitted destinations and bound resource use.
Quick Recap
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.
Recommended Free Tools

