Expand description
The official Rust runtime for AWS Lambda.
There are two mechanisms available for defining a Lambda function:
-
The
lambda
attribute macro, which generates the boilerplate to launch and run a Lambda function.The [
#[lambda]
] attribute must be placed on an asynchronous main function. However, as asynchronous main functions are not legal valid Rust this means that the main function must also be decorated using a [#[tokio::main]
] attribute macro. This is available from the [Tokio] crate. -
A type that conforms to the
Handler
trait. This type can then be passed to the thenetlify_lambda::run
function, which launches and runs the Lambda runtime.
An asynchronous function annotated with the #[lambda]
attribute must
accept an argument of type A
which implements serde::Deserialize
, a lambda::Context
and
return a Result<B, E>
, where B
implements [serde::Serializable
]. E
is
any type that implements Into<Box<dyn std::error::Error + Send + Sync + 'static>>
.
use netlify_lambda::{lambda, Context};
use serde_json::Value;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
#[lambda]
#[tokio::main]
async fn main(event: Value, _: Context) -> Result<Value, Error> {
Ok(event)
}
[#[tokio::main]
]: https://docs.rs/tokio/0.2.21/tokio/attr.main.html
[Tokio]: https://docs.rs/tokio/
Structs§
- Configuration derived from environment variables.
- The Lambda function execution context. The values in this struct are populated using the Lambda environment variables and the headers returned by the poll request to the Runtime APIs.
- A
Handler
implemented by a closure.
Traits§
- A trait describing an asynchronous function
A
toB
.
Functions§
- Returns a new
HandlerFn
with the given closure. - Starts the Lambda Rust runtime and begins polling for events on the Lambda Runtime APIs.
- Runs the lambda function almost entirely in-memory. This is meant for testing.
Attribute Macros§
- Wrap an async function into the lambda constructs