Vicuna

GitHub Actions crates.io Released API docs MIT licensed

AWS Lambdas in Rust made simple.

⚠️ Active Development: Vicuna's API has not stabalized and may change without warning between releases!

📦 Install

Add the following to your Cargo.toml file.

toml [dependencies] vicuna = "0.4.0"

🤸 Usage

💡 This crate is intended to be paired with the serverless-rust plugin.

Vicuna produces handlers which take in a Lambda request and produce an appropriate response. The simplest handler is the default_handler provided by the crate:

```rust use lambdahttp::lambda; use vicuna::defaulthandler;

fn main() { lambda!(default_handler()) } ```

Handlers can be composed from middleware which can handle the request-response lifecycle in an arbitrary fashion. For example, a middleware that adds a header to our response could look like this:

```rust use lambda_http::http::header::{HeaderName, HeaderValue}; use vicuna::Handler;

fn addheader(handler: Handler) -> Handler { Box::new(move |request, context| { // Resolve any upstream middleware into a response. let mut resp = handler(request, context)?; // Add our custom header to the response. resp.headersmut().insert( HeaderName::fromstatic("x-hello"), HeaderValue::fromstatic("world"), ); Ok(resp) }) } ```

Middleware are wrapped around handlers, which themselves produce a handler for chainable invocation:

```rust use lambdahttp::lambda; use vicuna::{defaulthandler, WrappingHandler};

fn main() { lambda!(defaulthandler() .wrapwith(sayhello) .wrapwith(add_header) .handler()) } ```