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
[]
= "0.2"
Within your application's source, use lando's macros.
#[macro_use]
extern crate lando;
# fn main() { }
Write your function using the gateway! macro. See it's documentation for more examples.
# extern crate lando;
gateway!;
#
Alternatively, you can also just attribute a bare handler fn
with #[lando]
# extern crate lando;
use ;
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.
[]
= ["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.