Crate lando [] [src]

Lando provides machinery for serverless HTTP Rust applications deployable on AWS lambda.

Lando extends the crowbar crate with type safe interfaces exposing API gateway proxy events as standard Rust http types. For convenience, lando re-exports http::Request and http::Response types.

AWS lambda is a ✨ managed ✨ service meaning that you do not need to own and operate any of the servers your application will run on, freeing you up to focus on your application, letting the platform scale your application to meet its needs.

Lando exports Rust functions as native CPython modules making it possible to embed handlers within aws' python3.6 runtime.

Usage

Add both lando and cpython as dependencies to your Cargo.toml

[dependencies]
lando = "0.1"
cpython = "0.1"

Within your lib, use the macros from both crates

This example is not tested
#[macro_use(gateway)]
extern crate lando;
// the following imports macros needed by the gateway macro
#[macro_use]
extern crate cpython;

And write your function using the gateway! macro:

gateway!(|_request, context| {
    println!("hi cloudwatch logs, this is {}", context.function_name());
    // return a basic 200 response
    Ok(lando::Response::new(()))
});

Packaging functions

Lando targets AWS Lambda's Python3.6 runtime. For your code to be usable in this execution environment, you need to compile your application as a dynamic library allowing it to be embedded within CPython. The gateway! macro does the all the integration for you, but cargo still needs to know the type of lib you are compiling.

You can configure cargo to build a dynamic library with the following toml. If you're using the gateway! macro as above, you need to use lambda for the library name (see the documentation for gateway! if you want to use something else).

[lib]
name = "lambda"
crate-type = ["cdylib"]

💡 dylib produces dynamic library embeddable in other languages. This and other link formats are described here

cargo build will then produce an aws deployable liblambda.so binary. Package this file in a zip file and its now deployable as an AWS Lambda function. Be sure to use the the Python 3.6 execution environment with the handler configured as liblambda.handler.

Because you're building a dynamic library, other libraries that you're dynamically linking against need to also be in the Lambda execution environment. The easiest way to do this is building in an environment similar to Lambda's, like this Docker container.

Macros

gateway

Macro to wrap a Lambda function handler for API gateway events.

Structs

LambdaContext

Provides a view into the context object available to Lambda functions.

Response

Represents an HTTP response

Enums

Body

Reprentation of reques and response bodies

Traits

RequestExt

Extentions for http::Request objects that provide access to API gateway features

Type Definitions

Request

A re-exported version of http::Request with a type parameter for body fixed to type lando::Body

Result

Result type for gateway functions