https://github.com/apache/openwhisk-runtime-rust
Apache OpenWhisk Runtime Rust supports Apache OpenWhisk functions written in Rust
https://github.com/apache/openwhisk-runtime-rust
apache cloud docker faas functions functions-as-a-service openwhisk openwhisk-runtime rust serverless serverless-architectures serverless-functions
Last synced: about 2 months ago
JSON representation
Apache OpenWhisk Runtime Rust supports Apache OpenWhisk functions written in Rust
- Host: GitHub
- URL: https://github.com/apache/openwhisk-runtime-rust
- Owner: apache
- License: apache-2.0
- Created: 2019-02-28T12:57:28.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-09-24T14:22:11.000Z (about 1 year ago)
- Last Synced: 2025-01-30T10:34:06.697Z (11 months ago)
- Topics: apache, cloud, docker, faas, functions, functions-as-a-service, openwhisk, openwhisk-runtime, rust, serverless, serverless-architectures, serverless-functions
- Language: Python
- Homepage: https://openwhisk.apache.org/
- Size: 185 KB
- Stars: 26
- Watchers: 27
- Forks: 18
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Apache OpenWhisk Runtime for Rust
[](http://www.apache.org/licenses/LICENSE-2.0)
[](https://github.com/apache/openwhisk-runtime-rust/actions/workflows/ci.yaml)
### Give it a try today
To use as a Docker action:
```
wsk action update myAction my_action.rs --docker openwhisk/action-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 {
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`.
For the return result, not only support `A JSON serde Value` but also support `Array serde Value`
So a simple `hello array` funtion would be:
```rust
extern crate serde_json;
use serde_derive::{Deserialize, Serialize};
use serde_json::{Error, Value};
pub fn main(args: Value) -> Result {
let output = ["a", "b"];
serde_json::to_value(output)
}
```
And support array result for sequence action as well, the first action's array result can be used as next action's input parameter.
So the function can be:
```rust
extern crate serde_json;
use serde_derive::{Deserialize, Serialize};
use serde_json::{Error, Value};
pub fn main(args: Value) -> Result {
let inputParam = args.as_array();
let defaultOutput = ["c", "d"];
match inputParam {
None => serde_json::to_value(defaultOutput),
Some(x) => serde_json::to_value(x),
}
}
```
### 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 "]
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/action-rust-v1.34
```