Skip to content

Commit c013ef0

Browse files
committed
example openwhisk-rust-simple-http-endpoint
1 parent 9eef07b commit c013ef0

File tree

7 files changed

+132
-0
lines changed

7 files changed

+132
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.serverless
2+
*.pyc
3+
*.pyo
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[workspace]
2+
members = ["test"]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<!--
2+
title: 'OpenWhisk Serverless Boilerplate example in Rust'
3+
description: 'This example shows a Serverless boilerplate in Rust.'
4+
layout: Doc
5+
platform: OpenWhisk
6+
language: Rust
7+
authorLink: 'https://github.com/jonee'
8+
authorName: 'Jonee Ryan Ty'
9+
-->
10+
# Serverless Boilerplate - OpenWhisk - Rust
11+
12+
(This example is largely based on the openwhisk-go-simple by James Thomas but adapted for Rust)
13+
14+
Make sure `serverless` is installed. [See installation guide](https://serverless.com/framework/docs/providers/openwhisk/guide/installation/).
15+
16+
You will also need to set up your OpenWhisk account credentials using environment variables or a configuration file. Please see the [this guide for more information](https://serverless.com/framework/docs/providers/openwhisk/guide/credentials/).
17+
18+
## 1. Install Project Dependencies
19+
`npm install` in this directory to download the modules from `package.json`.
20+
21+
## 2. Compile Rust Binary (Statically)
22+
23+
```
24+
$ cargo build --release --target x86_64-unknown-linux-musl
25+
```
26+
27+
## 3. Deploy
28+
`serverless deploy` or `sls deploy`. `sls` is shorthand for the Serverless CLI command
29+
30+
```
31+
Serverless: Packaging service...
32+
Serverless: Excluding development dependencies...
33+
Serverless: Compiling Functions...
34+
Serverless: Compiling Packages...
35+
Serverless: Compiling API Gateway definitions...
36+
Serverless: Compiling Rules...
37+
Serverless: Compiling Triggers & Feeds...
38+
Serverless: Compiling Service Bindings...
39+
Serverless: Deploying Functions...
40+
Serverless: Deploying API Gateway definitions...
41+
Serverless: Deployment successful!
42+
43+
44+
Service Information
45+
platform: us-south.functions.cloud.ibm.com
46+
namespace: _
47+
service: rust-service
48+
49+
actions:
50+
rust-service-dev-test_test
51+
```
52+
53+
## 4. Invoke deployed function
54+
`serverless invoke --function test_test` or `serverless invoke -f test_test`
55+
56+
`-f` is shorthand for `--function`
57+
58+
In your terminal window you should see the response from Apache OpenWhisk
59+
60+
```bash
61+
$ serverless invoke -f test_test
62+
{
63+
"message": "Serverless Rust Hello"
64+
}
65+
66+
```
67+
68+
**For more information on the Serverless OpenWhisk plugin, please see the project repository: [https://serverless.com/framework/docs/providers/openwhisk/guide/credentials/](https://serverless.com/framework/docs/providers/openwhisk/guide/credentials/).**
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "openwhisk-rust-simple-http-endpoint",
3+
"version": "0.1.0",
4+
"description": "Example demonstrates how to setup a simple Rust function with OpenWhisk.",
5+
"dependencies": {
6+
"serverless-openwhisk": ">=0.13.0"
7+
}
8+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
service: rust-service
2+
3+
provider:
4+
name: openwhisk
5+
runtime: binary
6+
# memorySize: 128
7+
# stage: api # we attach the stage ie dev or prod in the path
8+
9+
package:
10+
# individually: true # creates one artifact for each function
11+
exclude:
12+
- ./**
13+
include:
14+
- ./target/x86_64-unknown-linux-musl/release/test
15+
16+
# remember to run npm install to download the provider plugin.
17+
plugins:
18+
- serverless-openwhisk
19+
20+
21+
functions:
22+
test_test:
23+
handler: target/x86_64-unknown-linux-musl/release/test
24+
events:
25+
- http:
26+
path: test/test
27+
method: get
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "test"
3+
version = "0.1.0"
4+
edition = "2018"
5+
authors = ["jonee"]
6+
7+
[dependencies]
8+
tokio = { version = "0.2", features = ["macros"] }
9+
#lambda_http = { git = "https://github.com/awslabs/aws-lambda-rust-runtime/", branch = "master"}
10+
serde_json = "1.0"
11+
rustc-serialize = "0.3"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
use serde_json::json;
3+
4+
fn main() {
5+
6+
// creating an application/json response
7+
println!("{}", json!({
8+
"message": "Serverless Rust Hello"
9+
}))
10+
}
11+
12+
13+

0 commit comments

Comments
 (0)