Difficulty: beginner
Estimated Time: 8 minutes

Using Rules & Triggers with OpenShift Cloud Functions

In this scenario, you will deploy a simple nodejs timestamp function on the OpenShift Cloud Functions FaaS platform. You will then setup activation polling to show when the timestamp function is executed. After that, you will create a Rule and a Trigger to demonstrate how to use those features.

Currently, the setup of OpenWhisk takes up to 2.5 minutes. This setup was started when you started this scenario. It is recommended that you come back in 2.5 minutes to proceed with the first step in this scenario.


In this scenario you learned how to:

  • Write a simple timestamp function and deploy it.
  • Poll the activation logging.
  • Create a Trigger using the cron parameter of Alarm package feed.
  • Create a Rule tied to the Trigger and verify the execution of the function

Please take sometime to play with other related scenarios that are available to get yourself familiarized with various serverless concepts on OpenShift Cloud Functions. Good Luck!

Additional Resources

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Rules and Triggers on OCF

Step 1 of 3

Step 1 - Create Timestamp Function

Create Timestamp Function

1. Create a simple Timestamp JavaScript function

First, we need to create JavaScript file, click on the link below to create an empty file called timestamp.js in the directory /root/projects/ocf : timestamp.js

Once the created file is opened in the editor, you can then copy the content below into the file (or use the Copy to editor button):

function main(params) {
  var date = new Date();
  console.log("Invoked at: " + date.toLocaleString());
  return { message: "Invoked at: " + date.toLocaleString() };
Take a minute and review the timestamp.js. The function is pretty simple logging a message with the timestamp to the console and also returning that same message.

2. Deploy the function

Let's now deploy the function called timestamp to OpenWhisk:

cd /root/projects/ocf/

wsk -i action create timestamp timestamp.js

Lets check if the function is created correctly:

wsk -i action list | grep timestamp

The output of the command should show something like:

/whisk.system/timestamp                                  private nodejs:6