forked from serverless/serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding documentation for 0.5 release on openwhisk plugin.
New event sources for Cloudant and Message Hub. Support using plugin with local OpenWhisk deployments. Web Actions section for HTTP events without API Gw.
- Loading branch information
James Thomas
committed
Mar 11, 2017
1 parent
a42d7b3
commit 9c194ec
Showing
7 changed files
with
323 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<!-- | ||
title: Serverless Framework - Apache OpenWhisk Events - Cloudant DB | ||
menuText: Cloudant | ||
menuOrder: 4 | ||
description: Follow database modification events from IBM Cloudant with Apache OpenWhisk via the Serverless Framework | ||
layout: Doc | ||
--> | ||
|
||
<!-- DOCS-SITE-LINK:START automatically generated --> | ||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/openwhisk/events/cloudant) | ||
<!-- DOCS-SITE-LINK:END --> | ||
|
||
# Cloudant | ||
|
||
This event allows you to connect functions to [IBM Cloudant](https://cloudant.com/), a NoSQL database-as-a-service based upon [Apache CouchDB](http://couchdb.apache.org/). Functions are invoked for each database modification that occurs. | ||
|
||
This event utilise the trigger feed provided by the [Cloudant package](https://github.com/openwhisk/openwhisk-package-cloudant). | ||
|
||
## Setup | ||
|
||
[IBM Cloudant](https://cloudant.com/) instances can be provisioned through the [IBM Bluemix](https://console.ng.bluemix.net) platform. OpenWhisk on Bluemix will export Cloudant service credentials bound to a package with the following name: | ||
|
||
``` | ||
/${BLUEMIX_ORG}_${BLUEMIX_SPACE}/Bluemix_${SERVICE_NAME}_Credentials-1 | ||
``` | ||
|
||
## Configuration | ||
|
||
Users need to pass the database credentials and the database name to listen to changes on when defining the event. | ||
|
||
### Using Package Credentials | ||
|
||
Rather than having to manually define all authentication properties needed by the Cloudant trigger feed, you can reference a package which provides these properties as default parameters. | ||
|
||
Developers only need to add the database to listen to for each event. | ||
|
||
```yaml | ||
# serverless.yaml | ||
functions: | ||
index: | ||
handler: users.main | ||
events: | ||
- cloudant: | ||
package: /${BLUEMIX_ORG}_${BLUEMIX_SPACE}/Bluemix_${SERVICE_NAME}_Credentials-1 | ||
db: db_name | ||
|
||
``` | ||
|
||
The configuration will create a trigger called `${serviceName}_${fnName}_cloudant_${db}` and a rule called `${serviceName}_${fnName}_cloudant_${db}_rule` to bind the function to the database update events. | ||
|
||
The trigger and rule names created can be set explicitly using the `trigger` and `rule` parameters. | ||
|
||
### Using Manual Parameters | ||
|
||
Authentication credentials for the Cloudant event source can be defined explicitly, rather than using pulling credentials from a package. | ||
|
||
```yaml | ||
# serverless.yaml | ||
functions: | ||
index: | ||
handler: users.main | ||
events: | ||
- cloudant: | ||
host: xxx-yyy-zzz-bluemix.cloudant.com | ||
username: USERNAME | ||
password: PASSWORD | ||
db: db_name | ||
``` | ||
### Binding Multiple Functions | ||
Other functions can bind to the same database event being fired using the inline `trigger` event and referencing this trigger name. | ||
|
||
```yaml | ||
# serverless.yaml | ||
functions: | ||
index: | ||
handler: users.main | ||
events: | ||
- cloudant: | ||
package: /${BLUEMIX_ORG}_${BLUEMIX_SPACE}/Bluemix_${SERVICE_NAME}_Credentials-1 | ||
db: my_db | ||
trigger: db_events | ||
rule: connect_index_to_db | ||
another: | ||
handler: users.another | ||
events: | ||
- trigger: db_events | ||
``` | ||
|
||
## Event Details | ||
|
||
Functions are invoked with the JSON object returned by the [CouchDB changes feed](http://guide.couchdb.org/draft/notifications.html) for each database modification. The contents of the generated events have the following parameters: | ||
|
||
- `id`: The document ID. | ||
- `seq`: The sequence identifier that is generated by Cloudant. | ||
- `changes`: An array of objects, each of which has a `rev` field that contains the revision ID of the document. | ||
|
||
The JSON representation of the trigger event is as follows: | ||
|
||
```json | ||
{ | ||
"id": "6ca436c44074c4c2aa6a40c9a188b348", | ||
"seq": "2-g1AAAAL9aJyV-GJCaEuqx4-BktQkYp_dmIfC", | ||
"changes": [ | ||
{ | ||
"rev": "2-da3f80848a480379486fb4a2ad98fa16" | ||
} | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<!-- | ||
title: Serverless Framework - Apache OpenWhisk Events - IBM Message Hub | ||
menuText: Message Hub | ||
menuOrder: 4 | ||
description: Follow Apache Kafka queue messages from IBM's Message Hub service with Apache OpenWhisk via the Serverless Framework | ||
layout: Doc | ||
--> | ||
|
||
<!-- DOCS-SITE-LINK:START automatically generated --> | ||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/openwhisk/events/messagehub) | ||
<!-- DOCS-SITE-LINK:END --> | ||
|
||
# Message Hub | ||
|
||
This event allows you to connect functions to [IBM Message Hub](https://developer.ibm.com/messaging/message-hub/), a scalable message bus in the cloud, based upon [Apache Kafka](https://kafka.apache.org/). Functions are invoked with messages that are added to a Kafka topic. | ||
|
||
This event utilise the trigger feed provided by the [Message Hub package](https://github.com/openwhisk/openwhisk-package-kafka). | ||
|
||
## Setup | ||
|
||
[IBM Message Hub](https://developer.ibm.com/messaging/message-hub/) instances can be provisioned through the [IBM Bluemix](https://console.ng.bluemix.net) platform. OpenWhisk on Bluemix will export Message Hub service credentials bound to a package with the following name: | ||
|
||
``` | ||
/${BLUEMIX_ORG}_${BLUEMIX_SPACE}/Bluemix_${SERVICE_NAME}_Credentials-1 | ||
``` | ||
|
||
## Configuration | ||
|
||
Users need to pass the message hub credentials and the kafka topic to listen for messages on when defining the event. | ||
|
||
### Using Package Credentials | ||
|
||
Rather than having to manually define all authentication properties needed by the Message Hub trigger feed, you can reference a package which provides these properties as default parameters. | ||
|
||
Developers only need to add the kafka topic to listen for messages on with each event. | ||
|
||
```yaml | ||
# serverless.yaml | ||
functions: | ||
index: | ||
handler: users.main | ||
events: | ||
- messagehub: | ||
package: /${BLUEMIX_ORG}_${BLUEMIX_SPACE}/Bluemix_${SERVICE_NAME}_Credentials-1 | ||
topic: my_kafka_topic | ||
|
||
``` | ||
|
||
*Optional parameters `json`, `binary_key`, `binary_value` are also supported.* | ||
|
||
The configuration will create a trigger called `${serviceName}_${fnName}_messagehub_${db}` and a rule called `${serviceName}_${fnName}_messagehub_${db}_rule` to bind the function to the database update events. | ||
|
||
The trigger and rule names created can be set explicitly using the `trigger` and `rule` parameters. | ||
|
||
### Using Manual Parameters | ||
|
||
Authentication credentials for the Message Hub event source can be defined explicitly, rather than using pulling credentials from a package. | ||
|
||
```yaml | ||
# serverless.yaml | ||
functions: | ||
index: | ||
handler: users.main | ||
events: | ||
- message_hub: | ||
topic: my_kafka_topic | ||
brokers: afka01-prod01.messagehub.services.us-south.bluemix.net:9093 | ||
user: USERNAME | ||
password: PASSWORD | ||
admin_url: https://kafka-admin-prod01.messagehub.services.us-south.bluemix.net:443 | ||
json: true | ||
binary_key: true | ||
binary_value: true | ||
``` | ||
`topic`, `brokers`, `user`, `password` and `admin_url` are mandatory parameters. | ||
|
||
### Binding Multiple Functions | ||
|
||
Other functions can bind to the same database event being fired using the inline `trigger` event and referencing this trigger name. | ||
|
||
```yaml | ||
# serverless.yaml | ||
functions: | ||
index: | ||
handler: users.main | ||
events: | ||
- message_hub: | ||
package: /${BLUEMIX_ORG}_${BLUEMIX_SPACE}/Bluemix_${SERVICE_NAME}_Credentials-1 | ||
topic: my_kafka_topic | ||
trigger: log_events | ||
rule: connect_index_to_kafka | ||
another: | ||
handler: users.another | ||
events: | ||
- trigger: log_events | ||
``` | ||
|
||
## Event Details | ||
|
||
The payload of that trigger event will contain a `messages` field which is an array of messages that have been posted since the last time your trigger fired. | ||
|
||
The JSON representation of a sample event is as follows: | ||
|
||
```json | ||
{ | ||
"messages": [ | ||
{ | ||
"partition": 0, | ||
"key": "U29tZSBrZXk=", | ||
"offset": 421760, | ||
"topic": "mytopic", | ||
"value": "Some value" | ||
} | ||
] | ||
} | ||
``` | ||
For more details on the exact semantics of the message properties, please see the [trigger feed documentation](https://github.com/openwhisk/openwhisk-package-kafka). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!-- | ||
title: Serverless Framework - Apache OpenWhisk Guide - Web Actions | ||
menuText: Web Actions | ||
menuOrder: 6 | ||
description: Configuring Apache OpenWhisk Web Actions in the Serverless Framework | ||
layout: Doc | ||
--> | ||
|
||
<!-- DOCS-SITE-LINK:START automatically generated --> | ||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/openwhisk/guide/web-actions) | ||
<!-- DOCS-SITE-LINK:END --> | ||
|
||
# Web Actions | ||
|
||
Functions can be turned into ["*web actions*"](https://github.com/openwhisk/openwhisk/blob/master/docs/actions.md) which return HTTP content without use of an API Gateway. This feature is enabled by setting an annotation (`web-export`) in the configuration file. | ||
|
||
``` | ||
functions: | ||
my_function: | ||
handler: index.main | ||
annotations: | ||
web-export: true | ||
``` | ||
|
||
Functions with this annotation can be invoked through a URL template with the following parameters. | ||
|
||
``` | ||
https://{APIHOST}/api/v1/experimental/web/{USER_NAMESPACE}/{PACKAGE}/{ACTION_NAME}.{TYPE} | ||
``` | ||
|
||
- *APIHOST* - platform endpoint e.g. *openwhisk.ng.bluemix.net.* | ||
- *USER_NAMESPACE* - this must be an explicit namespace and cannot use the default namespace (_). | ||
- *PACKAGE* - action package or `default`. | ||
- *ACTION_NAME* - default form `${servicename}-${space}-${name}`. | ||
- *TYPE* - `.json`, `.html`, `.text` or `.http`. | ||
|
||
Return values from the function are used to construct the HTTP response. The following parameters are supported. | ||
|
||
1. `headers`: a JSON object where the keys are header-names and the values are string values for those headers (default is no headers). | ||
2. `code`: a valid HTTP status code (default is 200 OK). | ||
3. `body`: a string which is either plain text or a base64 encoded string (for binary data). | ||
|
||
Here is an example of returning HTML content: | ||
|
||
```javascript | ||
function main(args) { | ||
var msg = "you didn't tell me who you are." | ||
if (args.name) { | ||
msg = `hello ${args.name}!` | ||
} | ||
return {body: | ||
`<html><body><h3><center>${msg}</center></h3></body></html>`} | ||
} | ||
``` | ||
|
||
Here is an example of returning binary data: | ||
|
||
```javascript | ||
function main() { | ||
let png = <base 64 encoded string> | ||
return { | ||
headers: { "Content-Type": "image/png" }, | ||
body: png }; | ||
} | ||
``` | ||
|
||
Functions can access request parameters using the following environment variables. | ||
|
||
1. `**__ow_meta_verb:**` the HTTP method of the request. | ||
2. `**__ow_meta_headers:**` the request headers. | ||
3. `**__ow_meta_path:**` the unmatched path of the request. | ||
|
||
Full details on this new feature are available in this [blog post](https://medium.com/openwhisk/serverless-http-handlers-with-openwhisk-90a986cc7cdd#.2x09176m8). | ||
|
||
**\*IMPORTANT: [Web Actions](https://github.com/openwhisk/openwhisk/blob/master/docs/actions.md) is currently experimental and may be subject to breaking changes.*** |