netlify_lambda_http 0.1.0

Application Load Balancer and API Gateway event types for AWS Lambda
Documentation
Enriches the `lambda` crate with [`http`](https://github.com/hyperium/http) types targeting AWS [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html), [API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html) REST and HTTP API lambda integrations. This crate abstracts over all of these trigger events using standard [`http`](https://github.com/hyperium/http) types minimizing the mental overhead of understanding the nuances and variation between trigger details allowing you to focus more on your application while also giving you to the maximum flexibility to transparently use whichever lambda trigger suits your application and cost optimiztions best. # Examples ## Hello World `lambda_http` handlers adapt to the standard `lambda::Handler` interface using the [`handler`](fn.handler.html) function. The simplest case of an http handler is a function of an `http::Request` to a type that can be lifted into an `http::Response`. You can learn more about these types [here](trait.IntoResponse.html). Adding an `#[lambda(http)]` attribute to a `#[tokio::run]`-decorated `main` function will setup and run the Lambda function. Note: this comes at the expense of any onetime initialization your lambda task might find value in. The full body of your `main` function will be executed on **every** invocation of your lambda task. ```rust,no_run use netlify_lambda_http::{ lambda::{lambda, Context}, IntoResponse, Request, }; type Error = Box; #[lambda(http)] #[tokio::main] async fn main(_: Request, _: Context) -> Result { Ok("👋 world!") } ``` ## Hello World, Without Macros For cases where your lambda might benfit from one time function initializiation might prefer a plain `main` function and invoke `netlify_lambda::run` explicitly in combination with the [`handler`](fn.handler.html) function. Depending on the runtime cost of your dependency bootstrapping, this can reduce the overall latency of your functions execution path. ```rust,no_run use netlify_lambda_http::{handler, lambda}; type Error = Box; #[tokio::main] async fn main() -> Result<(), Error> { // initialize dependencies once here for the lifetime of your // lambda task netlify_lambda::run(handler(|request, context| async { Ok("👋 world!") })).await?; Ok(()) } ``` ## Leveraging trigger provided data You can also access information provided directly from the underlying trigger events, like query string parameters, with the [`RequestExt`](trait.RequestExt.html) trait. ```rust,no_run use netlify_lambda_http::{handler, lambda::{self, Context}, IntoResponse, Request, RequestExt}; type Error = Box; #[tokio::main] async fn main() -> Result<(), Error> { netlify_lambda::run(handler(hello)).await?; Ok(()) } async fn hello( request: Request, _: Context ) -> Result { Ok(format!( "hello {}", request .query_string_parameters() .get("name") .unwrap_or_else(|| "stranger") )) } ```