Expand description
A framework for AWS Lambda functions in Rust: fast, small and correct by default, so the code you write is the business logic.
davidrs is a thin layer over the official runtime crates: it keeps
lambda_runtime/lambda_http and the AWS SDK as the transport, adds
an ordered pipeline in the same process as your handler, and owns the
surrounding invocation logic:
- One absolute deadline per invocation.
Deadlineis a monotonic instant; child budgets cannot outlive their parent, and every adapter keeps a cleanup margin before Lambda’s own timeout. - One ordered pipeline per trigger. HTTP requests (
http::Apibuffered,http::stream::StreamApistreamed) run their boundary checks, authorization and handler in order. Both render failures before the response starts; a streamed body reports later errors through the stream. SQS (queue), EventBridge (event), schedules (schedule) and direct invocations (runtime) decode their payload before the handler and report its failures to Lambda. - Safe error rendering. A
http::Failurecarries a public message and a separate internal detail; the built-in renderers use a fixed string for every 5xx. - Explicit limits. Buffered requests, bounded upstream readers, decompressed payloads, paginated reads, retries and stream producers have limits and report when they hit them.
- Honest partial outcomes. SQS batches report failures per record,
PutEventsandBatchWriteItemper entry, a bounded read says whether it is complete. - Access and limits by configuration.
http::access::Accessdecides who is calling, for which tenant and with what permission;http::RateLimitedcounts requests across every instance.
It is deliberately not a web framework: one Lambda serves one operation, so
there is no router, no middleware stack, no dependency-injection container
and no ORM. Application state is an ordinary struct the handler receives as
Arc<App>; persistence uses the SDK’s own builders.
§Features
default = []. The empty crate is RuntimeError, Invocation,
Deadline, Context and the environment readers — value types with no
runtime, no HTTP and no AWS SDK. Every capability is additive, named after
what it enables, and never quietly enables an unrelated one: a binary
compiles exactly the capabilities its Cargo.toml asks for.
| Feature | Enables |
|---|---|
runtime | runtime::run: the native Lambda loop over a typed payload |
http | http::Api: the buffered API Gateway / Function URL pipeline, http::access, http::RateLimited, http::fields |
http-stream | http::stream: streamed JSON and server-sent events with CORS and content negotiation |
apigw-rest | REST API proxy events next to HTTP API |
alb | Application Load Balancer events in the buffered pipeline |
streaming | streaming: response bodies that own their producer |
queue, queue-visibility | queue: SQS partial-batch processing, visibility changes |
event, schedule | event, schedule: typed EventBridge and scheduled payloads |
aws | aws::sdk_config: SDK configuration from the Lambda environment |
dynamo | dynamo: bounded DynamoDB reads and writes, cursors, spans |
eventbridge | eventbridge: EventBridge publishing with per-entry outcomes |
secrets | secrets: typed Secrets Manager reads that never echo a value |
client | client: an outbound reqwest client with byte and time limits |
auth | auth: RS256 / JWKS token verification with a bounded refresh |
cache | cache: in-process caches (Moka) |
compression | compression: gzip with a cap on the decoded size |
digest | digest: SHA-256 and hex for identifiers and cache keys |
validate, problem | Garde validation and RFC 9457 problem details |
logs, metrics, otel | telemetry: logs, EMF metrics and X-Ray traces |
test-support | test_support: synthetic invocations and requests |
mcp, mcp-openapi | mcp: an MCP server with hand-written tools, or tools from an OpenAPI document |
§Where to start
The guide is organized by the job in front of you. Read
guide::introduction to decide whether the crate
fits, then guide::getting_started, which builds
one function and shows the JSON a caller receives. After that, open the
chapter for the trigger or service you are deploying. The guide’s examples
are compiled and tested. examples/ in the repository holds one runnable
program per trigger.
Modules§
- auth
- Bearer-token verification: RS256 signatures checked against a JWKS that is refreshed in a bounded, coalesced way.
- aws
- SDK configuration for a Lambda sandbox, without
aws-config. - cache
- In-process caches:
moka’s own types, re-exported. - client
- Outbound HTTP with explicit limits.
- compression
- Gzip with a cap on the decoded size.
- digest
- SHA-256 and lowercase hex, for identifiers and cache keys.
- dynamo
- DynamoDB helpers for the parts every data layer gets wrong, and nothing else.
- event
- Typed EventBridge input.
- eventbridge
- Publishing to EventBridge with per-entry outcomes.
- guide
- The developer guide: why
davidrsexists, how an invocation moves through it, and how to use each capability without rediscovering the failure it was written to prevent. - http
- The buffered HTTP pipeline for API Gateway and Function URL requests.
- mcp
- An MCP server from one Lambda function: tools an AI client lists and calls, over Streamable HTTP.
- queue
- SQS consumers with per-record failure reporting.
- runtime
- The native Lambda loop over any typed payload.
- schedule
- Typed scheduled input.
- secrets
- Reading secrets from AWS Secrets Manager.
- streaming
- Response streaming where the producer is owned by the response.
- telemetry
- Logs, metrics and traces: three independent features.
- test_
support - Builders for testing handlers, without a live AWS account.
Structs§
- Context
- What a handler receives besides its own input: the invocation, and the scope its caller was authorized with.
- Deadline
- An absolute point in time after which work must stop.
- Invocation
- Identity and timing of one Lambda invocation.
Enums§
- Runtime
Error - A failure of configuration, of a budget, of a bound, or of anything else that is not a request’s own fault.
Functions§
- error_
chain - Formats an error and every
sourcebehind it as one line. - list_
env - A comma-separated list, each entry trimmed, empty entries dropped.
- optional_
env - A variable that may be absent:
Nonewhen it is unset, empty or blank. - required_
env - A variable the function cannot run without.