Apache openwhisk

Clone this repo:
  1. 4382a6d update readme with usage instructions (#16) by Roberto Diaz · 4 days ago master
  2. 08ecf7a gradle version 5 (#17) by David Grove · 7 days ago
  3. d2406e9 add .asf.yaml to configure github metadata (#15) by David Grove · 3 weeks ago
  4. c763f09 tlp: remove incubator references (#14) by David Grove · 8 weeks ago
  5. d6f3025 gradlew licensing (#13) by David Grove · 3 months ago

Apache OpenWhisk Runtime for Rust

License Build Status

Give it a try today

To use as a Docker action:

wsk action update myAction my_action.rs --docker openwhisk/actionloop-rust-v1.34

The file my_action.rs looks like:

extern crate serde_json;

use serde_derive::{Deserialize, Serialize};
use serde_json::{Error, Value};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
struct Input {
    #[serde(default = "stranger")]
    name: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
struct Output {
    body: String,
}

fn stranger() -> String {
    "stranger".to_string()
}

pub fn main(args: Value) -> Result<Value, Error> {
    let input: Input = serde_json::from_value(args)?;
    let output = Output {
        body: format!("Hello, {}", input.name),
    };
    serde_json::to_value(output)
}

The action is mainly composed by a main function that accepts a JSON serdes Value as input and returns a Result including a JSON serde Value.

Managing dependencies

If your action needs external dependencies, you need to provide a zip file including your source and your cargo file with all your dependencies. The folder structure is the following:

|- Cargo.toml
|- src
    |- lib.rs

Here is an example of a Cargo.toml file

[package]
name = "actions"
version = "0.1.0"
authors = ["John Doe <john@doe.domain>"]
edition = "2018"

[dependencies]
serde_json = "1.0"
serde = "1.0"
serde_derive = "1.0"

Once you have all your code zipped in a file with the showed folder structure you can generate your action with the following command:

wsk action create yourAction /full_path_to/yourCode.zip --docker openwhisk/actionloop-rust-v1.34