Git Product home page Git Product logo

rust-crowbar's Introduction

rust-crowbar

Build Status 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.2"
cpython = "0.1"

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. If you're using the lambda! macro as above, you need to use lambda for the library name (see the documentation for lambda! if you want to use something else).

[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. 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.

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 using that is available at ilianaw/crowbar-builder on Docker Hub.

Contributing

crowbar welcomes your contributions:

  • Let us know if you use crowbar in production
  • If you have a bug report or an idea, submit an issue
  • If you want something to work on, check the issues list
  • Please submit non-trivial changes as an issue first; send a pull request when the implementation is agreed on

crowbar follows a code of conduct; please read it.

rust-crowbar's People

Contributors

iliana avatar arcnmx avatar mockersf avatar therustmonk avatar naftulikay avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.