Skip to content

Commit 3aa5a98

Browse files
authored
Merge pull request #572 from jonee/master
Rust examples for OpenWhisk and AWS
2 parents bcefe77 + 663d5ae commit 3aa5a98

File tree

15 files changed

+295
-0
lines changed

15 files changed

+295
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ serverless install -u https://github.com/serverless/examples/tree/master/folder-
114114
| [Serverless Telegram Bot](https://github.com/serverless/examples/tree/master/aws-python-telegram-bot) <br/> This example demonstrates how to setup an echo Telegram Bot using the Serverless Framework ⚡🤖 | python |
115115
| [Aws Ruby Line Bot](https://github.com/serverless/examples/tree/master/aws-ruby-line-bot) <br/> Example demonstrates how to setup a simple Line echo bot on AWS | ruby |
116116
| [Aws Ruby Simple Http Endpoint](https://github.com/serverless/examples/tree/master/aws-ruby-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint | ruby |
117+
| [Aws Rust Simple Http Endpoint](https://github.com/serverless/examples/tree/master/aws-rust-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint with rust | nodeJS |
117118
| [Azure Nodejs](https://github.com/serverless/examples/tree/master/azure-node-line-bot) <br/> Azure Functions sample for the Serverless framework | nodeJS |
118119
| [Azure Node Simple Http Endpoint](https://github.com/serverless/examples/tree/master/azure-node-simple-http-endpoint) <br/> An example of making http endpoints with the Azure Functions Serverless Framework plugin | nodeJS |
119120
| [Azure Nodejs](https://github.com/serverless/examples/tree/master/azure-node-telegram-bot) <br/> Azure Functions sample for the Serverless framework | nodeJS |
@@ -135,6 +136,7 @@ serverless install -u https://github.com/serverless/examples/tree/master/folder-
135136
| [Openwhisk Python Simple Http Endpoint](https://github.com/serverless/examples/tree/master/openwhisk-python-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint with OpenWhisk. | python |
136137
| [Openwhisk Python Simple](https://github.com/serverless/examples/tree/master/openwhisk-python-simple) <br/> Example demonstrates how to setup a simple Python function with OpenWhisk. | python |
137138
| [Openwhisk Ruby Simple](https://github.com/serverless/examples/tree/master/openwhisk-ruby-simple) <br/> Example demonstrates how to setup a simple Ruby function with OpenWhisk. | ruby |
139+
| [Openwhisk Rust Simple Http Endpoint](https://github.com/serverless/examples/tree/master/openwhisk-rust-simple-http-endpoint) <br/> Example demonstrates how to setup a simple Rust function with OpenWhisk. | nodeJS |
138140
| [Openwhisk Swift Package With Precompiled Binaries](https://github.com/serverless/examples/tree/master/openwhisk-swift-precompiled-binaries) <br/> Swift packages and pre-compiled binaries on OpenWhisk. | swift |
139141
| [Openwhisk Swift Scheduled Cron](https://github.com/serverless/examples/tree/master/openwhisk-swift-scheduled-cron) <br/> Example of creating a Swift function that runs as a cron job using the serverless schedule event. | swift |
140142
| [Openwhisk Swift Simple Http Endpoint](https://github.com/serverless/examples/tree/master/openwhisk-swift-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP endpoint using Swift function with OpenWhisk. | swift |
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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!--
2+
title: 'AWS Serverless Boilerplate example in Rust'
3+
description: 'This example shows a Serverless boilerplate in Rust.'
4+
layout: Doc
5+
framework: v1+
6+
platform: AWS
7+
language: Rust
8+
authorLink: 'https://github.com/jonee'
9+
authorName: 'Jonee Ryan Ty'
10+
authorAvatar:
11+
-->
12+
13+
# Serverless Boilerplate - AWS - Rust
14+
15+
Make sure `serverless` is installed. [See installation guide](https://serverless.com/framework/docs/providers/AWS/guide/installation/).
16+
17+
You will also need to set up your AWS account credentials using environment variables or a configuration file. Please see the [this guide for more information](https://serverless.com/framework/docs/providers/AWS/guide/credentials/).
18+
19+
## 1. Install Project Dependencies
20+
`npm install` in this directory to download the modules from `package.json`.
21+
22+
## 2. Compile Rust Binary
23+
24+
```
25+
$ cargo build --release
26+
```
27+
28+
## 3. Deploy
29+
30+
Hackish way to deploy
31+
32+
1. Run `sls deploy` which would give an error about missing file path in the package path.
33+
2. If you look at .serverless it should have 3 files-
34+
35+
cloudformation-template-create-stack.json
36+
cloudformation-template-update-stack.json
37+
serverless-state.json
38+
39+
3. rename .serverless folder to p
40+
4. cargo build --release then add aws-rust-simple-http-endpoint.zip which consists of target/release/test only to the p folder
41+
5. sls deploy --package p
42+
43+
44+
45+
46+
## 4. Invoke deployed function
47+
48+
```bash
49+
$ curl https://***.execute-api.us-east-1.amazonaws.com/dev/test/test
50+
{"message":"Serverless Rust Hello"}
51+
```
52+
53+
**For more information on the Serverless AWS plugin, please see the project repository: [https://serverless.com/framework/docs/providers/AWS/guide/credentials/](https://serverless.com/framework/docs/providers/AWS/guide/credentials/).**
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "aws-rust-simple-http-endpoint",
3+
"version": "0.0.1",
4+
"description": "Example demonstrates how to setup a simple HTTP GET endpoint with rust",
5+
"author": "Jonee Ryan Ty",
6+
"devDependencies": {
7+
"serverless-rust": "^0.3.8"
8+
}
9+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
service: aws-rust-simple-http-endpoint
2+
3+
#frameworkVersion: ">=1.28.0 <2.0.0"
4+
5+
provider:
6+
name: aws
7+
runtime: rust
8+
# memorySize: 128
9+
# stage: api # we attach the stage ie dev or prod in the path
10+
region: us-east-1 # make sure your region is correct
11+
12+
package:
13+
# individually: true # creates one artifact for each function
14+
exclude:
15+
- ./**
16+
include:
17+
- ./target/release/test
18+
19+
plugins:
20+
- serverless-rust
21+
22+
functions:
23+
test_test:
24+
handler: test
25+
events:
26+
- http:
27+
path: test/test
28+
method: get
29+
30+
custom:
31+
# this section allows for customization of the default
32+
# serverless-rust plugin settings
33+
rust:
34+
# flags passed to cargo
35+
# cargoFlags: '--features enable-awesome'
36+
# experimental! when set to true, artifacts are built locally outside of docker
37+
dockerless: true
38+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
use lambda_http::{handler, lambda, IntoResponse, Request, Context};
3+
use serde_json::json;
4+
5+
type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
6+
7+
#[tokio::main]
8+
async fn main() -> Result<(), Error> {
9+
lambda::run(handler(test)).await?;
10+
Ok(())
11+
}
12+
13+
14+
async fn test(_: Request, _: Context) -> Result<impl IntoResponse, Error> {
15+
16+
17+
// `serde_json::Values` impl `IntoResponse` by default
18+
// creating an application/json response
19+
Ok(json!({
20+
"message": "Serverless Rust Hello"
21+
}))
22+
}
23+
24+
/*
25+
#[cfg(test)]
26+
mod tests {
27+
use super::*;
28+
29+
#[tokio::test]
30+
async fn test_handles() {
31+
let request = Request::default();
32+
let expected = json!({
33+
"message": "Serverless Rust Hello"
34+
})
35+
.into_response();
36+
let response = test(request, Context::default())
37+
.await
38+
.expect("expected Ok(_) value")
39+
.into_response();
40+
assert_eq!(response.body(), expected.body())
41+
}
42+
}
43+
*/
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"]

0 commit comments

Comments
 (0)