The Simplest Way to Make Lambda and Selenium Work Like They Should
Running lambda and selenium together lets teams automate browsers without managing servers. A serverless function starts a headless browser, runs web tasks, and shuts down. This setup works well for web tests, site checks, and data collection. Teams can run hundreds of browser tasks at the same time on demand. You pay only for the seconds your browser tasks take to run. Yet getting a heavy browser to fit inside a small function takes care. How lambda and selenium share roles, keys, and data
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Running lambda and selenium together lets teams automate browsers without managing servers. A serverless function starts a headless browser, runs web tasks, and shuts down.
This setup works well for web tests, site checks, and data collection. Teams can run hundreds of browser tasks at the same time on demand. You pay only for the seconds your browser tasks take to run. Yet getting a heavy browser to fit inside a small function takes care.
How lambda and selenium share roles, keys, and data
First, an event triggers the cloud function to start a new run. The function loads a custom image or layer that holds the browser binary. It also loads the matching browser driver into memory at the same time. Next, the function uses its cloud role to read secrets from a store. These secrets hold the login keys needed for the target web app. Then, the browser script starts up and opens the target web page.
The script fills out forms, clicks buttons, and reads text from the page. When the task ends, the function writes the output to a storage bucket. It also sends run logs to your central log tool for review. The cloud platform then freezes or stops the function container right away. Each run must clean up temporary browser files so disk space stays free. If old files stay in the temporary folder, the next run might crash.
Common failure modes and how to scope roles and networks
Many teams make mistakes when they set up credentials for browser scripts. A common error is putting plain text passwords inside function variables. Anyone who can view the function settings in the console can see them. Another mistake is using one shared login account for every single browser run. When a shared account breaks or gets locked, every automated check stops working. It also makes it hard to see which task changed data on a page.
Broad cloud roles create another big risk for your serverless browser tasks. If a function role can read all secrets, a bad script can steal them. You should give each function its own narrow role with strict rules. That role should only read the exact secret needed for its single task. You should also place the function inside a private network subnet. Use strict network rules to control which web hosts the browser can reach. Log every browser step and mask sensitive fields like emails or phone numbers. Masking rewrites matched fields in results before the function saves any logs.
Lambda Execution Roles + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Managing browser binaries and memory limits in production
Web browsers use a lot of memory and CPU power when they load pages. Small functions will freeze or crash if you give them too little memory. You should test your tasks and set a generous memory limit for each run. Container images often work better than layers when packaging large browser binaries. An image lets you bundle the exact browser and driver together before deployment. This prevents version mismatches that stop the browser from starting up in production.
Always close the browser and quit the driver before the function finishes its run. Leftover browser processes can hang the container and waste your cloud budget. Set a clear timeout on both the browser steps and the cloud function itself. Make sure the browser timeout is shorter than the main function timeout. This gives your code time to log errors and clean up before shutdown.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
Why does my headless browser crash inside a cloud function?
Browsers often crash in functions due to low memory or full temporary disk space. Give the function more memory and delete temporary files after every single run.
Should I use layers or container images for lambda and selenium?
Container images are often easier when you need to bundle big browser binaries. They give you more space and let you test the exact setup locally.
How should browser scripts log in to internal web apps?
Put your app credentials in a secret store and use a scoped function role. Fetch the login key in memory during the run and never log it.
Related guides
In this post