https://github.com/curology/vicuna
🦙 AWS Lambdas in Rust, made simple.
https://github.com/curology/vicuna
aws-lambdas lambda middleware serverless serverless-framework
Last synced: 2 months ago
JSON representation
🦙 AWS Lambdas in Rust, made simple.
- Host: GitHub
- URL: https://github.com/curology/vicuna
- Owner: curology
- License: mit
- Created: 2019-12-12T16:17:14.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-29T20:56:01.000Z (about 4 years ago)
- Last Synced: 2025-04-15T02:12:01.843Z (2 months ago)
- Topics: aws-lambdas, lambda, middleware, serverless, serverless-framework
- Language: Rust
- Homepage:
- Size: 32.2 KB
- Stars: 24
- Watchers: 9
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Vicuna
[](https://github.com/PocketDerm/vicuna/actions) [](https://crates.io/crates/vicuna) [](http://docs.rs/vicuna) [](./LICENSE)
> AWS Lambdas in Rust made simple.
- Simple, middleware-based interface
- Naturally modular design
- Purpose-built for [`serverless-rust`](https://www.npmjs.com/package/serverless-rust)> ⚠️ **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.1"
```## 🤸 Usage
> 💡 This crate is intended to be paired with the [`serverless-rust`](https://www.npmjs.com/package/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 vicuna::{default_handler, lambda_http::lambda};fn main() {
lambda!(default_handler())
}
```Handlers can be composed from middleware which can handle the request-response
lifecycle in an arbitrary fashion. For example, custom middleware can be
written like so:```rust
use vicuna::Handler;fn my_middleware(handler: Handler) -> Handler {
Box::new(move |request, context| {
// Resolve upstream middleware chain into a response...
let mut response = handler(request, context);
// ...mutate response as desired.
response
})
}
```Middleware are wrapped around handlers, which themselves produce a handler for
chainable invocation:```rust
use vicuna::lambda_http::lambda;
use vicuna::middleware::{body, header};
use vicuna::{default_handler, error, Handler, WrappingHandler};fn main() {
lambda!(default_handler::()
.wrap_with(body("Hello, world!"))
.wrap_with(header("x-foo", "bar"))
.handler())
}
```