[][src]Crate lambda_runtime

Lambda runtime makes it easy to run Rust code inside AWS Lambda. To create Lambda function with this library simply include it as a dependency, make sure that you declare a function that respects the Handler type, and call the start() function from your main method. The executable in your deployment package must be called bootstrap.

use lambda_runtime::{error::HandlerError, lambda, Context};
use simple_error::bail;
use serde_derive::{Serialize, Deserialize};

#[derive(Deserialize, Clone)]
struct CustomEvent {
    first_name: String,
    last_name: String,
}

#[derive(Serialize, Clone)]
struct CustomOutput {
    message: String,
}

fn main() {
    lambda!(my_handler);
}

fn my_handler(e: CustomEvent, ctx: Context) -> Result<CustomOutput, HandlerError> {
    if e.first_name == "" {
        bail!("Empty first name");
    }
    Ok(CustomOutput{
        message: format!("Hello, {}!", e.first_name),
    })
}

Modules

error

The error module exposes the HandlerError type.

Macros

lambda

Initializes the Lambda runtime with the given handler. Optionally this macro can also receive a customized instance of Tokio runtime to drive internal lambda operations to completion

Structs

Context

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 new instance of the Context object is passed to each handler invocation.

Traits

Handler

Functions acting as a handler must conform to this type.

Functions

start

Creates a new runtime and begins polling for events using Lambda's Runtime APIs.