Skip to main content

Crate davidrs

Crate davidrs 

Source
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. Deadline is 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::Api buffered, http::stream::StreamApi streamed) 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::Failure carries 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, PutEvents and BatchWriteItem per entry, a bounded read says whether it is complete.
  • Access and limits by configuration. http::access::Access decides who is calling, for which tenant and with what permission; http::RateLimited counts 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.

FeatureEnables
runtimeruntime::run: the native Lambda loop over a typed payload
httphttp::Api: the buffered API Gateway / Function URL pipeline, http::access, http::RateLimited, http::fields
http-streamhttp::stream: streamed JSON and server-sent events with CORS and content negotiation
apigw-restREST API proxy events next to HTTP API
albApplication Load Balancer events in the buffered pipeline
streamingstreaming: response bodies that own their producer
queue, queue-visibilityqueue: SQS partial-batch processing, visibility changes
event, scheduleevent, schedule: typed EventBridge and scheduled payloads
awsaws::sdk_config: SDK configuration from the Lambda environment
dynamodynamo: bounded DynamoDB reads and writes, cursors, spans
eventbridgeeventbridge: EventBridge publishing with per-entry outcomes
secretssecrets: typed Secrets Manager reads that never echo a value
clientclient: an outbound reqwest client with byte and time limits
authauth: RS256 / JWKS token verification with a bounded refresh
cachecache: in-process caches (Moka)
compressioncompression: gzip with a cap on the decoded size
digestdigest: SHA-256 and hex for identifiers and cache keys
validate, problemGarde validation and RFC 9457 problem details
logs, metrics, oteltelemetry: logs, EMF metrics and X-Ray traces
test-supporttest_support: synthetic invocations and requests
mcp, mcp-openapimcp: 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 davidrs exists, 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§

RuntimeError
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 source behind it as one line.
list_env
A comma-separated list, each entry trimmed, empty entries dropped.
optional_env
A variable that may be absent: None when it is unset, empty or blank.
required_env
A variable the function cannot run without.