Crate gateway [] [src]

Gateway extends the crowbar crate making it possible to write type safe AWS Lambda functions in Rust that are invoked by API gateway events.

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


Add both gateway and cpythonto your Cargo.toml:

gateway = "0.1"
cpython = "0.1"

Use macros from both crates:

Be careful when using this code, it's not being tested!
extern crate gateway;
// the following imports macros needed by the gateway macro
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

Packaging functions

For your code to be usable in AWS Lambda's Python3.6 execution environment, you need to compile to a dynamic library with the necessary functions for CPython to run. The gateway! macro does most of this for you, but cargo still needs to know what to do.

You can configure cargo to build a dynamic library with the following. 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).

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

Note: cdylib exports C interface from a Rust dynamic library.

Link formats are described here

cargo build will now build a Put this in a zip file and upload it to an AWS Lambda function. Use 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, such as Amazon Linux. You can use an EC2 instance or a Docker container.


pub use response::Response;
pub use request::Request;



Request types


Response types



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



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

Type Definitions


Result type for API Gateway requests