[][src]Crate lando

Lando provides building blocks for serverless HTTP Rust applications deployable on AWS Lambda.

Specifically, lando exposes API Gateway proxy events as standard Rust http types with API Gateway modeled Bodies. For convenience, lando re-exports http::Request and http::Response.

AWS Lambda is a ✨ fully managed ✨ compute service allowing you to run code without thinking about servers. AWS will provide monitoring metrics and scaling out of the box for you.

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

Usage

Add lando to your Cargo.toml

[dependencies]
lando = "0.2"

Within your application's source, use lando's macros.

#[macro_use]
extern crate lando;

Write your function using the gateway! macro. See it's documentation for more examples.

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

Alternatively, you can also just attribute a bare handler fn with #[lando]

use lando::{Request, LambdaContext, IntoResponse, Result};

#[lando]
fn handler(
    _: Request,
    _: LambdaContext
) -> Result<impl IntoResponse> {
    Ok(())
}

Packaging functions

Lando targets AWS Lambda's Python3.6 runtime. The gateway! macro does the all the integration for you, but cargo still needs to know what type of lib you are compiling. Cargo makes it easy to produce compatible binaries.

Simply add the following setting to your crate's Cargo.toml file.

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

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

cargo build will then produce an AWS deploy-ready liblambda.so binary artifact on linux hosts. Package this file in a zip file and it's now deployable as an AWS Lambda function! Be sure to use the the Python 3.6 execution environment with the handler configured as lib{your_crate_name}.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 achive this is by building in an environment similar to Lambda's. This Docker container faithfully reproduces the AWS Lambda Python 3.6 runtime.

Re-exports

pub extern crate http;
pub extern crate lando_attr;
pub use request::GatewayRequest;

Modules

request

API Gateway request types. Typically these are exposed via the request_context method provided by lando::RequestExt

Macros

gateway

A macro that exposes a Lambda function handler for AWS API gateway proxy event triggers.

Structs

LambdaContext

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

Response

Represents an HTTP response

StrMap

A read-only view into a map of string data

Enums

Body

Representation of http request and response bodies as supported by API Gateway.

PayloadError

Payload deserialization errors

Traits

IntoResponse

A conversion of self into a Response

RequestExt

Extentions for lando::Request structs 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