Skip to content

Wrapper to simplify writing AWS Lambda functions in Rust (using the Python execution environment)

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

ChristopherMacGown/rust-crowbar

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

rust-crowbar

crates.io docs.rs

crowbar makes it easy to write AWS Lambda functions in Rust. It wraps native Rust functions into CPython modules that handle converting Python objects into Rust objects and back again.

Usage

Add both crowbar and cpython to your Cargo.toml:

[dependencies]
crowbar = "0.1"
cpython = { version = "*", default-features = false, features = ["python27-sys"] }

Use macros from both crates:

#[macro_use(lambda)]
extern crate crowbar;
#[macro_use]
extern crate cpython;

And write your function using the lambda! macro:

lambda!(|event, context| {
    println!("hi cloudwatch logs, this is {}", context.function_name());
    // return the event without doing anything with it
    Ok(event)
});

Building Lambda functions

For your code to be usable in AWS Lambda's Python execution environment, you need to compile to a dynamic library with the necessary functions for CPython to run. The lambda! 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. Note that the library name must be lambda.

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

cargo build will now build a liblambda.so. Put this in a zip file and upload it to an AWS Lambda function. You will need to use the Python 2.7 execution environment with the handler configured as liblambda.handler.

For best results, it's important to build the shared library on a system using the same libraries as the Lambda execution environment. Since Lambda uses Amazon Linux, the easiest way to do this is to use an EC2 instance or a Docker container.

The builder directory of the crowbar git repo contains a Dockerfile with Rust set up and a build script to dump a zip file containing a stripped shared library to stdout. Documentation for that is available at ilianaw/crowbar-builder on Docker Hub.

About

Wrapper to simplify writing AWS Lambda functions in Rust (using the Python execution environment)

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 96.8%
  • Shell 3.2%