Skip to content

Commit fe713a8

Browse files
author
James Thomas
committedJan 25, 2017
Adding new OpenWhisk examples.
Added HTTP events, schedule events and function chaining examples.
1 parent 8e5ddc5 commit fe713a8

File tree

16 files changed

+361
-9
lines changed

16 files changed

+361
-9
lines changed
 

‎README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ Have an example? Submit a PR or [open an issue](https://github.com/serverless/ex
4949
| [Aws Alexa Skill](https://github.com/serverless/examples/tree/master/aws-python-alexa-skill) <br/> This example demonstrates how to use an AWS Lambdas for your custom Alexa skill. | python |
5050
| [Aws Scheduled Cron](https://github.com/serverless/examples/tree/master/aws-python-scheduled-cron) <br/> Example of creating a function that runs as a cron job using the serverless `schedule` event | python |
5151
| [Aws Simple Http Endpoint](https://github.com/serverless/examples/tree/master/aws-python-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint with python | python |
52-
| [Openwhisk Node Simple](https://github.com/serverless/examples/tree/master/openwhisk-node-simple) <br/> Boilerplate project repository for OpenWhisk provider with Serverless Framework. | nodeJS |
52+
| [Openwhisk Node Chaining Functions](https://github.com/serverless/examples/tree/master/openwhisk-node-chaining-functions) <br/> Example of chaining function calls using sequences and the sdk. | nodeJS |
53+
| [Openwhisk Node Scheduled Cron](https://github.com/serverless/examples/tree/master/openwhisk-node-scheduled-cron) <br/> Example of creating a function that runs as a cron job using the serverless schedule event. | nodeJS |
54+
| [Openwhisk Node Simple Http](https://github.com/serverless/examples/tree/master/openwhisk-node-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint with OpenWhisk. | nodeJS |
55+
| [Openwhisk Node Simple](https://github.com/serverless/examples/tree/master/openwhisk-node-simple) <br/> Simple example demonstrating OpenWhisk provider support. | nodeJS |
5356

5457
<!-- AUTO-GENERATED-CONTENT:END -->
5558

@@ -67,7 +70,9 @@ Have an example? Submit a PR or [open an issue](https://github.com/serverless/ex
6770
| **[Keboola Developer Portal](https://github.com/keboola/developer-portal)** <br/> Keboola developer portal built with Serverless | [keboola](http://github.com/keboola) |
6871
| **[Pfs Email Serverless](https://github.com/SCPR/pfs-email-serverless)** <br/> This is a lambda function created by the serverless framework. It searches through members in our mongodb who have not been sent emails and sends them an email with their custom token to unlock the pledge free stream. It then marks those members off as already receiving the email. | [SCPR](http://github.com/SCPR) |
6972
| **[Plaid Cashburndown Service](https://github.com/cplee/cashburndown-service)** <br/> Service for calculating cash burndown with plaid. Frontend code can be found here: https://github.com/cplee/cashburndown-site | [cplee](http://github.com/cplee) |
73+
| **[Sc5 Serverless Boilerplate](https://github.com/SC5/sc5-serverless-boilerplate)** <br/> A boilerplate that contains setup for test-driven development | [SC5](http://github.com/SC5) |
7074
| **[Serverless Aws Rekognition Finpics](https://github.com/rgfindl/finpics)** <br/> Use AWS Rekognition to provide a faces search of finpics.com | [rgfindl](http://github.com/rgfindl) |
75+
| **[Serverless Blog To Podcast](https://github.com/SC5/serverless-blog-to-podcast)** <br/> Service that reads RSS feed and converts the entries to a podcast feed and audio files using Amazon Polly | [SC5](http://github.com/SC5) |
7176
| **[Serverless Cloudwatch Rds Custom Metrics](https://github.com/AndrewFarley/serverless-cloudwatch-rds-custom-metrics)** <br/> A NodeJS-based MySQL RDS Data Collection script to push Custom Metrics to Cloudwatch with Serverless | [AndrewFarley](http://github.com/AndrewFarley) |
7277
| **[Serverless Delivery Framework](https://github.com/99xt/serverless-delivery-framework)** <br/> This is a boilerplate for version release pipeline with serverless framework | [99xt](http://github.com/99xt) |
7378
| **[Serverless Facebook Quotebot](https://github.com/pmuens/quotebot)** <br/> 100% Serverless Facebook messenger chatbot which will respond with inspiring quotes | [pmuens](http://github.com/pmuens) |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Serverless Boilerplate - OpenWhisk - Node.js
2+
3+
Make sure `serverless` is installed. [See installation guide](https://serverless.com/framework/docs/providers/openwhisk/guide/installation/).
4+
5+
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/aws/guide/credentials/).
6+
7+
## 1. Install Provider Plugin
8+
`npm install -g serverless-openwhisk`
9+
10+
## 2. Install Service Dependencies
11+
`npm install` in this directory to download the modules from `package.json`.
12+
13+
## 3. Deploy
14+
`serverless deploy` or `sls deploy`. `sls` is shorthand for the Serverless CLI command
15+
16+
Make a note of the API endpoint that is logged to the console during deployment.
17+
18+
```
19+
Serverless: Configured API endpoint: https://xxx-yyy-zzz-gws.api-gw.mybluemix.net/my_service
20+
```
21+
22+
## 4. Invoke sequence function
23+
`serverless invoke --function chained_seq --data '{"message": "a b c d e"}'`
24+
25+
`-f` is also shorthand for `--function`
26+
27+
In your terminal window you should see the response from Apache OpenWhisk
28+
29+
```bash
30+
{
31+
"message": "e d c b a"
32+
}
33+
```
34+
35+
## 5. Invoke chained function
36+
`serverless invoke --function manual_seq --data '{"message": "a b c d e"}'`
37+
38+
`-f` is also shorthand for `--function`
39+
40+
In your terminal window you should see the response from Apache OpenWhisk
41+
42+
```bash
43+
{
44+
"message": "e d c b a"
45+
}
46+
```
47+
48+
**For more information on the Serverless OpenWhisk plugin, please see the project repository: [https://serverless.com/framework/docs/providers/aws/guide/credentials/](https://serverless.com/framework/docs/providers/aws/guide/credentials/).**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
function chain(parameters) {
4+
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
5+
const ow = require('openwhisk')();
6+
7+
const invoke = (actionName, params) => ow.actions.invoke({ actionName, params, blocking: true });
8+
return invoke('my_service-dev-split', parameters)
9+
.then(res => invoke('my_service-dev-reverse', res.response.result))
10+
.then(res => invoke('my_service-dev-join', res.response.result))
11+
.then(res => res.response.result);
12+
}
13+
14+
module.exports.chain = chain;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "openwhisk-node-chaining-functions",
3+
"version": "0.1.0",
4+
"description": "Example of chaining function calls using sequences and the sdk.",
5+
"scripts": {
6+
"postinstall": "npm link serverless-openwhisk",
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Welcome to Serverless!
2+
#
3+
# This file is the main config file for your service.
4+
# It's very minimal at this point and uses default values.
5+
# You can always add more config options for more control.
6+
# We've included some commented out config examples here.
7+
# Just uncomment any of them to get that config option.
8+
#
9+
# For full config options, check the docs:
10+
# docs.serverless.com
11+
#
12+
# Happy Coding!
13+
14+
service: my_service # NOTE: update this with your service name
15+
16+
provider:
17+
name: openwhisk
18+
19+
functions:
20+
split:
21+
handler: utils.split
22+
reverse:
23+
handler: utils.reverse
24+
join:
25+
handler: utils.join
26+
chained_seq:
27+
sequence:
28+
- split
29+
- reverse
30+
- join
31+
manual_seq:
32+
handler: handler.chain
33+
34+
# remember to run npm install to download the provider plugin.
35+
plugins:
36+
- serverless-openwhisk
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
function split(params) {
4+
return { message: params.message.split(' ') };
5+
}
6+
7+
function join(params) {
8+
return { message: params.message.join(' ') };
9+
}
10+
11+
function reverse(params) {
12+
return { message: params.message.reverse() };
13+
}
14+
15+
module.exports.split = split;
16+
module.exports.join = join;
17+
module.exports.reverse = reverse;
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Serverless Boilerplate - OpenWhisk - Node.js
2+
3+
Make sure `serverless` is installed. [See installation guide](https://serverless.com/framework/docs/providers/openwhisk/guide/installation/).
4+
5+
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/aws/guide/credentials/).
6+
7+
## 1. Install Provider Plugin
8+
`npm install -g serverless-openwhisk`
9+
10+
## 2. Install Service Dependencies
11+
`npm install` in this directory to download the modules from `package.json`.
12+
13+
## 3. Deploy
14+
`serverless deploy` or `sls deploy`. `sls` is shorthand for the Serverless CLI command
15+
16+
Make a note of the API endpoint that is logged to the console during deployment.
17+
18+
```
19+
Serverless: Configured API endpoint: https://xxx-yyy-zzz-gws.api-gw.mybluemix.net/my_service
20+
```
21+
22+
## 4. Invoke deployed function
23+
`serverless invoke --function time` or `serverless invoke -f time`
24+
25+
`-f` is shorthand for `--function`
26+
27+
In your terminal window you should see the response from Apache OpenWhisk
28+
29+
```bash
30+
{
31+
"payload": "The time in Europe/London is: 16:01:14."
32+
}
33+
```
34+
35+
## 5. Test HTTP endpoint
36+
37+
Use a HTTP client to access the endpoint for your function. The endpoint will
38+
be the API gateway root path, logged during deployment, and your configured
39+
function path.
40+
41+
```
42+
$ http get https://xxx-yyy-zzz-gws.api-gw.mybluemix.net/my_service/time
43+
{
44+
"payload": "The time in Europe/London is: 16:01:07."
45+
}
46+
$ http get https://xxx-yyy-zzz-gws.api-gw.mybluemix.net/my_service/time?timezone=Europe/Berlin
47+
{
48+
"payload": "The time in Europe/Berlin is: 17:01:11."
49+
}
50+
```
51+
52+
**For more information on the Serverless OpenWhisk plugin, please see the project repository: [https://serverless.com/framework/docs/providers/aws/guide/credentials/](https://serverless.com/framework/docs/providers/aws/guide/credentials/).**
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
function cron() {
4+
const time = new Date();
5+
const name = '__OW_ACTION_NAME';
6+
console.log(`Your cron function "${process.env[name]}" ran at ${time}`); // eslint-disable-line no-console
7+
}
8+
9+
module.exports.cron = cron;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "openwhisk-node-scheduled-cron",
3+
"version": "0.1.0",
4+
"description": "Example of creating a function that runs as a cron job using the serverless schedule event.",
5+
"scripts": {
6+
"postinstall": "npm link serverless-openwhisk",
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Welcome to Serverless!
2+
#
3+
# This file is the main config file for your service.
4+
# It's very minimal at this point and uses default values.
5+
# You can always add more config options for more control.
6+
# We've included some commented out config examples here.
7+
# Just uncomment any of them to get that config option.
8+
#
9+
# For full config options, check the docs:
10+
# docs.serverless.com
11+
#
12+
# Happy Coding!
13+
14+
service: my_service # NOTE: update this with your service name
15+
16+
provider:
17+
name: openwhisk
18+
19+
functions:
20+
cron:
21+
handler: handler.cron
22+
events:
23+
- schedule: cron(* * * * *)
24+
25+
# remember to run npm install to download the provider plugin.
26+
plugins:
27+
- serverless-openwhisk
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Serverless Boilerplate - OpenWhisk - Node.js
2+
3+
Make sure `serverless` is installed. [See installation guide](https://serverless.com/framework/docs/providers/openwhisk/guide/installation/).
4+
5+
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/aws/guide/credentials/).
6+
7+
## 1. Install Provider Plugin
8+
`npm install -g serverless-openwhisk`
9+
10+
## 2. Install Service Dependencies
11+
`npm install` in this directory to download the modules from `package.json`.
12+
13+
## 3. Deploy
14+
`serverless deploy` or `sls deploy`. `sls` is shorthand for the Serverless CLI command
15+
16+
Make a note of the API endpoint that is logged to the console during deployment.
17+
18+
```
19+
Serverless: Configured API endpoint: https://xxx-yyy-zzz-gws.api-gw.mybluemix.net/my_service
20+
```
21+
22+
## 4. Invoke deployed function
23+
`serverless invoke --function time` or `serverless invoke -f time`
24+
25+
`-f` is shorthand for `--function`
26+
27+
In your terminal window you should see the response from Apache OpenWhisk
28+
29+
```bash
30+
{
31+
"payload": "The time in Europe/London is: 16:01:14."
32+
}
33+
```
34+
35+
## 5. Test HTTP endpoint
36+
37+
Use a HTTP client to access the endpoint for your function. The endpoint will
38+
be the API gateway root path, logged during deployment, and your configured
39+
function path.
40+
41+
```
42+
$ http get https://xxx-yyy-zzz-gws.api-gw.mybluemix.net/my_service/time
43+
{
44+
"payload": "The time in Europe/London is: 16:01:07."
45+
}
46+
$ http get https://xxx-yyy-zzz-gws.api-gw.mybluemix.net/my_service/time?timezone=Europe/Berlin
47+
{
48+
"payload": "The time in Europe/Berlin is: 17:01:11."
49+
}
50+
```
51+
52+
**For more information on the Serverless OpenWhisk plugin, please see the project repository: [https://serverless.com/framework/docs/providers/aws/guide/credentials/](https://serverless.com/framework/docs/providers/aws/guide/credentials/).**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const moment = require('moment-timezone');
4+
5+
function time(params) {
6+
const timezone = params.timezone || 'Europe/London';
7+
const timestr = moment().tz(timezone).format('HH:MM:ss');
8+
9+
return { payload: `The time in ${timezone} is: ${timestr}.` };
10+
}
11+
12+
module.exports.time = time;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "openwhisk-node-simple-http",
3+
"version": "0.1.0",
4+
"description": "Example demonstrates how to setup a simple HTTP GET endpoint with OpenWhisk.",
5+
"scripts": {
6+
"postinstall": "npm link serverless-openwhisk",
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"dependencies": {
10+
"moment-timezone": "^0.5.11"
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Welcome to Serverless!
2+
#
3+
# This file is the main config file for your service.
4+
# It's very minimal at this point and uses default values.
5+
# You can always add more config options for more control.
6+
# We've included some commented out config examples here.
7+
# Just uncomment any of them to get that config option.
8+
#
9+
# For full config options, check the docs:
10+
# docs.serverless.com
11+
#
12+
# Happy Coding!
13+
14+
service: my_service # NOTE: update this with your service name
15+
16+
provider:
17+
name: openwhisk
18+
19+
functions:
20+
time:
21+
handler: handler.time
22+
events:
23+
- http: GET time
24+
25+
# remember to run npm install to download the provider plugin.
26+
plugins:
27+
- serverless-openwhisk

‎openwhisk-node-simple/README.md

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
# Serverless Boilerplate - OpenWhisk - Node.js
22

3-
A Serverless Framework Boilerplate for OpenWhisk support with Node.js
3+
Make sure `serverless` is installed. [See installation guide](https://serverless.com/framework/docs/providers/openwhisk/guide/installation/).
44

5-
**Please see [instructions](https://github.com/serverless/serverless-openwhisk) for getting starting with the OpenWhisk plugin for The Serverless Framework. The README walks you through setting up this project.**
5+
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/aws/guide/credentials/).
6+
7+
## 1. Install Provider Plugin
8+
`npm install -g serverless-openwhisk`
9+
10+
## 2. Install Service Dependencies
11+
`npm install` in this directory to download the modules from `package.json`.
12+
13+
## 3. Deploy
14+
`serverless deploy` or `sls deploy`. `sls` is shorthand for the Serverless CLI command
15+
16+
## 4. Invoke deployed function
17+
`serverless invoke --function hello_world` or `serverless invoke -f hello_world`
18+
19+
`-f` is shorthand for `--function`
20+
21+
In your terminal window you should see the response from Apache OpenWhisk
22+
23+
```bash
24+
{
25+
"payload": "Hello, World!"
26+
}
27+
```
28+
29+
Congrats you have just deployed and run your Hello World function!
30+
31+
**For more information on the Serverless OpenWhisk plugin, please see the project repository: [https://serverless.com/framework/docs/providers/aws/guide/credentials/](https://serverless.com/framework/docs/providers/aws/guide/credentials/).**
632

7-
https://github.com/serverless/serverless-openwhisk

‎openwhisk-node-simple/package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
{
22
"name": "openwhisk-node-simple",
33
"version": "0.1.0",
4-
"description": "Boilerplate project repository for OpenWhisk provider with Serverless Framework.",
4+
"description": "Simple example demonstrating OpenWhisk provider support.",
55
"scripts": {
6+
"postinstall": "npm link serverless-openwhisk",
67
"test": "echo \"Error: no test specified\" && exit 1"
78
},
8-
"author": "James Thomas <james@jamesthom.as>",
9-
"license": "MIT",
109
"dependencies": {
11-
"left-pad": "^1.1.3",
12-
"serverless-openwhisk": "serverless/serverless-openwhisk"
10+
"left-pad": "^1.1.3"
1311
}
1412
}

0 commit comments

Comments
 (0)
Please sign in to comment.