Run AWS Lambda handlers locally. No Docker, no SAM, no AWS connection required.
Project description
lambdarunner
Run AWS Lambda handlers locally. No Docker, no SAM, no AWS connection required.
Installation
pip install lambdarunner
Or with pipx for global CLI use:
pipx install lambdarunner
Quickstart
Given a handler file handler.py:
def lambda_handler(event, context):
return {
"statusCode": 200,
"body": f"Hello {event.get('name', 'World')}"
}
Run it:
# With an event file
lambdarunner invoke handler.lambda_handler -e event.json
# With inline JSON
lambdarunner invoke handler.lambda_handler --event '{"name": "Lambda"}'
# With a custom timeout
lambdarunner invoke handler.lambda_handler -e event.json -t 10
# With environment variables
lambdarunner invoke handler.lambda_handler --env-file .env --region eu-west-1
# With event from stdin
echo '{"name": "Pipe"}' | lambdarunner invoke handler.lambda_handler -e -
# Watch mode (re-invoke on file changes)
lambdarunner invoke handler.lambda_handler -e event.json --watch
# With AWS mocking (boto3 calls intercepted by moto)
lambdarunner invoke handler.lambda_handler -e event.json --mock-aws
Watch mode requires: pip install lambdarunner[watch]
Mock AWS mode requires: pip install lambdarunner[mock]
Event Templates
Generate ready-to-use event JSON for the most common Lambda trigger types:
# List all available templates
lambdarunner template
# Print a template to the terminal
lambdarunner template s3
lambdarunner template sqs
lambdarunner template sns
lambdarunner template eventbridge
lambdarunner template apigw # API Gateway REST API (v1)
lambdarunner template apigw-v2 # API Gateway HTTP API (v2)
Save to file and use with invoke:
# Bash / Zsh (Linux, macOS)
lambdarunner template s3 > event.json
lambdarunner invoke handler.lambda_handler --event event.json
# PowerShell 7 (pwsh)
lambdarunner template s3 > event.json
# PowerShell 5 (Windows PowerShell)
# Use Out-File to ensure UTF-8 encoding (plain `>` produces UTF-16 in PS5)
lambdarunner template s3 | Out-File -Encoding utf8 event.json
CLI Options
| Flag | Short | Default | Description |
|---|---|---|---|
--event |
-e |
{} |
Path to a JSON file, inline JSON string, or - for stdin |
--timeout |
-t |
30 |
Timeout in seconds |
--memory |
-m |
128 |
Simulated memory limit in MB |
--env-file |
None |
Path to a .env file to load |
|
--region |
us-east-1 |
Simulated AWS_DEFAULT_REGION |
|
--profile |
None |
AWS profile name for context | |
--pretty / --no-pretty |
True |
Pretty print JSON output | |
--traceback |
False |
Show full traceback on handler errors | |
--watch |
-w |
False |
Re-invoke on handler file changes |
--mock-aws |
False |
Start a local moto server and redirect boto3 calls to it | |
--version |
-V |
Show version and exit |
Mock AWS
Use --mock-aws to intercept all boto3 calls with moto — no AWS account, no credentials, no Docker required.
# handler.py
import boto3
def lambda_handler(event, context):
s3 = boto3.client("s3")
s3.create_bucket(Bucket="my-bucket")
s3.put_object(Bucket="my-bucket", Key="hello.txt", Body=b"world")
obj = s3.get_object(Bucket="my-bucket", Key="hello.txt")
return {"body": obj["Body"].read().decode()}
lambdarunner invoke handler.lambda_handler --mock-aws
boto3 is redirected to a local moto server automatically — no @mock_aws decorators needed in your handler code.
Note: AWS state (buckets, tables, queues, etc.) is reset on every invocation. In --watch mode, each file-change re-invoke starts with a fresh mock environment.
Shell Completion
Enable tab completion for your shell:
lambdarunner --install-completion
Supports Bash, Zsh, Fish, and PowerShell.
Why lambdarunner?
- Built from scratch with modern Python (3.12+)
- Polished CLI experience with Typer + Rich
- Faithful Lambda Context simulation, including
get_remaining_time_in_millis() - Real timeout handling with process isolation via
multiprocessing
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lambdarunner-0.6.1.tar.gz.
File metadata
- Download URL: lambdarunner-0.6.1.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.3 CPython/3.14.3 Linux/6.17.0-1010-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e118576cff422b4dd70586ba27c03aa848cfac5ffd199b30c6bd34856299134
|
|
| MD5 |
85f229a60d398ac0b214e393a805ec92
|
|
| BLAKE2b-256 |
7f0f3449215f3170a01125d4c2743de3aa6bcf59f83a333d9e881b0b9a640dde
|
File details
Details for the file lambdarunner-0.6.1-py3-none-any.whl.
File metadata
- Download URL: lambdarunner-0.6.1-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.3 CPython/3.14.3 Linux/6.17.0-1010-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f76dc7935f1d73f4e7224bf3b43b1c2ec9c6fdc0bb2d7e15e2edcfc484669f5f
|
|
| MD5 |
98264789eb4fbd733a7f92947f395e47
|
|
| BLAKE2b-256 |
b2e3a4af25f996a2cf25c1886d2e3aa123d623efd226d47c9e8dbaf749e07ed1
|