Difficulty: Intermediate
Estimated Time: 5-10 minutes

Building and Deploying serverless applications with Apache Openwhisk

By the end of this session you should be able to :

  • Build serverless application
  • Deploy an OpenWhisk application
  • Invoke actions on the app

Getting Started with Apache OpenWhisk

Deep dive

Building your Serverless application

We'll build a simple application that fetches weather data.

Start by creating an app.js file.

touch app.js

Then, paste the following content into the file.

var request = require('request');

function main(params) {
    var location = params.location || 'Kisumu';
    var url = 'https://query.yahooapis.com/v1/public/yql?q=select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="' + location + '")&format=json';

    return new Promise(function(resolve, reject) {
        request.get(url, function(error, response, body) {
            if (error) {
            else {
                var condition = JSON.parse(body).query.results.channel.item.condition;
                var text = condition.text;
                var temperature = condition.temp;
                var output = 'It is ' + temperature + ' degrees in ' + location + ' and ' + text;
                resolve({msg: output});

Next, create the action ./wsk/wsk action create weather app.js

Then let's invoke the action. ./wsk/wsk action invoke --result --param location "Nairobi,KE"

We can also deploy the app by doing the following:

Create an app manifest : touch manifest.yaml

And paste the following into the manifest file.

                function: app.js

Then deploy ./wskdeploy/wskdeploy -m manifest.yaml