Crate lando [−] [src]
Lando provides building blocks 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 ✨ fully managed ✨ compute service meaning that you do not need to own or operate any of the servers your application will run on, freeing you up to focus on your application. You can consider Lambda AWS's Function-As-A-Service offering.
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]
cpython = "0.1"
lando = "0.1"
Within your libraries source, use the macros from both crates
// the following imports macros needed by the gateway macro #[macro_use] extern crate cpython; #[macro_use(gateway)] extern crate lando;
And write your function using the gateway! macro
gateway!(|_request, context| { println!("👋 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 what 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 artifact.
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 achive this is by building in an environment similar to Lambda's, like this Docker container.
Macros
gateway |
Macro that exposes a Lambda function handler for AWS API gateway proxy event triggers. |
Structs
LambdaContext |
Provides a view into the |
Response |
Represents an HTTP response |
Enums
Body |
Representation of http request and response bodies |
Traits
RequestExt |
Extentions for |
Type Definitions
Request |
A re-exported version of |
Result |
Result type for gateway functions |