lambda_runtime 0.2.0

Rust runtime for AWS Lambda

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),
    })
}