Spin up headless browsers on AWS in under a minuteβno layers, no EC2, no pain.
Star β this repo if it saves you hours, and hit Fork to make it yours in seconds.
# 1. Clone this repository
git clone https://github.com/your-username/browserbase-lambda-playwright.git
cd browserbase-lambda-playwright
# 2. Deploy infrastructure
env | grep AWS || export AWS_ACCESS_KEY_ID=... && export AWS_SECRET_ACCESS_KEY=...
cd infra && pip install -r requirements.txt && cdk deploy --all --require-approval never
# 3. Fetch API details from CloudFormation outputs
echo "export API_ENDPOINT_URL=$(aws cloudformation describe-stacks \
--stack-name BrowserbaseLambdaStack \
--query 'Stacks[0].Outputs[?OutputKey==`ApiEndpointUrl`].OutputValue' \
--output text)"
echo "export API_KEY=$(aws apigateway get-api-key \
--api-key $(aws cloudformation describe-stacks --stack-name BrowserbaseLambdaStack \
--query 'Stacks[0].Outputs[?OutputKey==`ApiKeyId`].OutputValue' --output text) \
--include-value \
--query 'value' \
--output text)"
# 4. Install example dependencies and run quick start
pip install -r examples/requirements.txt
python examples/quick_start.py# 1. Fork or push this repo to your GitHub account
# 2. Add repository secrets under Settings β Secrets & variables β Actions:
# - AWS_ACCESS_KEY
# - AWS_SECRET_ACCESS_KEY
# 3. Create Browserbase secrets in AWS Secrets Manager (see infra/stack.py env names)
# 4. Push to main β GitHub Actions triggers CDK deployYou now have a Lambda that opens a Browserbase session and runs Playwright code from lambdas/scraper/scraper.py.
Invoke it with:
curl -X POST "$API_ENDPOINT_URL" \
-H "Content-Type: application/json" \
-H "x-api-key: $API_KEY" \
-d '{"url":"https://news.ycombinator.com/"}' \
-v
# β¦then poll status:
curl -H "x-api-key: $API_KEY" "$API_ENDPOINT_URL/<jobId>"OR
pip install -r examples/requirements.txt
python examples/quick_start.py
- POST /scrape returns 202 Accepted immediately.
- Job metadata is stored in DynamoDB (
JobStatusTable) with status updates (PENDINGΒ β RUNNINGΒ β SUCCESS/FAILED). - GET /scrape/{jobId} polls DynamoDB for the latest job result.
- Zero binary juggling β Playwright lives in the Lambda image; Chrome runs remotely on Browserbase.
- Cold-start βΒ 2Β s β no browser download, just connect-over-CDP.
- Pay-per-run β pure Lambda pricing; scale by upgrading Browserbase, not infra.
- Async, serverless β fire-and-forget POST, durable job tracking via DynamoDB.
- Built-in CI/CD β GitHub Actions deploys on every push to
main/staging.
ββββββββββββββ CDP (WebSocket) ββββββββββββββ
β AWS Lambda β βββββββββββββββββΆ β Browserbaseβ
ββββββββββββββ ββββββββββββββ
β Logs
βΌ
AWS CloudWatch
β
βΌ
Amazon DynamoDB (JobStatusTable)
.
βββ .github/workflows/deploy.yaml
βββ examples/
β βββ quick_start.py
β βββ requirements.txt
βββ infra/
β βββ app.py
β βββ cdk.json
β βββ requirements.txt
β βββ stack.py
βββ lambdas/
β βββ getter/
β β βββ Dockerfile
β β βββ getter.py
β β βββ requirements.txt
β βββ scraper/
β βββ Dockerfile
β βββ scraper.py
β βββ requirements.txt
βββ .gitignore
βββ README.md
βββ LICENSE
π Full Setup & Prerequisites
| Tool | Version |
|---|---|
| AWS CLI | any 2.x |
| Docker | β₯ 20.10 |
| Node & npm | any LTS |
| Python | 3.12+ |
| Browserbase account | free tier OK |
# macOS (Homebrew)
brew install awscli(See AWS docs for Windows/Linux.)
aws configure # supply keys & default region, e.g. us-east-1aws secretsmanager create-secret \
--name BrowserbaseLambda/BrowserbaseApiKey \
--secret-string '{"BROWSERBASE_API_KEY":"$BROWSERBASE_API_KEY"}'
aws secretsmanager create-secret \
--name BrowserbaseLambda/BrowserbaseProjectId \
--secret-string '{"BROWSERBASE_PROJECT_ID":"$BROWSERBASE_PROJECT_ID"}'pip install playwright && python -m playwright install| Question | Answer |
|---|---|
| Browserbase free tier? | Yesβ1 concurrent session; creation rateβlimited. |
| Coldβstarts? | Typical <Β 2β―s (CDP connect, no browser download). |
| Add extra Python libs? | Add to `lambdas/<getter |
| API returns 202 Acceptedβhow to track status? | Poll GET /scrape/{jobId} to read status/results from DynamoDB. |
If you need faster cold-starts or shorter CI deploys, consider:
-
Provisioned Concurrency: Keep your Lambda warm to skip container startup.
-
Browserbase KeepβAlive: Paid sessions remove free-tier spinβup overhead.
-
CI Caching: Use actions/cache for pip and npm in GitHub Actions to shave minutes
Pull requests are welcome! Please open an issue first if you plan a large change.
This project is licensed under the MIT License β see the LICENSE file for details.