vicuna 0.1.3

AWS Lambdas made simple.
docs.rs failed to build vicuna-0.1.3
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: vicuna-0.4.1

Vicuna

AWS Lambdas in Rust made simple.

  • Simple, middleware-based interface
  • Naturally modular design
  • Purpose-built for serverless-rust

📦 Install

Add the following to your Cargo.toml file.

[dependencies]
vicuna = "0.1.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:

use lambda_http::lambda;
use vicuna::default_handler;

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:

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

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

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

use lambda_http::{lambda, IntoResponse, Request, Response};
use lambda_runtime::{error::HandlerError, Context};
use vicuna::HasMiddleware;

fn hello_lambda(req: Request, _: Context) -> Result<impl IntoResponse, HandlerError> {
    // Middleware is applied in reverse order!
    let handler = default_handler().wrap_with(say_hello).wrap_with(add_header);

    // Coerce errors into `failure::Error`.
    Ok(handler(req).map_err(|e| -> failure::Error { e.into() })?)
}

fn main() {
    lambda!(hello_lambda)
}