Pragmatism in the real world

Getting started with Serverless PHP

I've been interested in Apache OpenWhisk for a little while now and recently submitted a new feature to add PHP support to the project. As OpenWhisk is a serverless environment, most users do not run their own copy and instead use a commercial provider with IBMs Bluemix available now along with Adobes I/O Runtime and RedHat coming soon. As a result, my contribution, isn't practically useful until it's in production with a provider. Fortunately, and… continue reading.

Logging in to Bluemix via wsk

To set up the authentication for the OpenWhisk cli tool wsk you do this: $ wsk property set –apihost {host} –auth {key} > /dev/null $ wsk property unset –namespace > /dev/null The host and key are provided to from your OpenWhisk supplier. For Bluemix OpenWhisk, you can find it by logging in and then going to the Download OpenWhisk CLI page. To make my life easier, I use a bash function to swap OpenWhisk environments… continue reading.

Creating an OpenWhisk Alexa skill

In a previous post, I looked at the mechanics of how to create an Alexa skill to tell me which colour bin I needed to put out next. I'll now look at how I chose to implement it in OpenWhisk, using Swift. An Alexa skill consists of a number of intents and you register a single end point to handle them all. As I'm using OpenWhisk, I have direct web access to my actions without… continue reading.

Getting started writing an Alexa Skill

We now have 4 Amazon Echo devices in the house, and, inspired by a demo LornaJane gave me at DPC, I have decided to write some skills for it. This article covers what I learnt in order to get my first Swift skill working. Our bins are collected by the council every other week; one week it's the green recycling bin and the other week, it's the black waste bin. Rather than looking it up,… continue reading.

Switching OpenWhisk environments

When developing with OpenWhisk, it's useful to use separate environments for working locally or on the cloud for development, staging and production of your application. In OpenWhisk terms, this means setting the host and the API key for your wsk command line application. $ wsk property set –apihost $host –auth $key (Of course, for live and staging, ideally, you will be using a build server!) For a Vagrant install of OpenWhisk, the host is 192.168.33.13… continue reading.

POSTing data using KituraNet

I had a need to send a POST request with a JSON body from Swift and as I had KituraNet and SwiftyJSON already around, it proved to reasonably easy. To send a POST request using KituraNet, I wrote this code: let url = "http://httpbin.org/post". // Change to the actual URL let dataToSend = ["foo": ["bar": "baz"]] // Change to the actual data // body needs to be of type Data, use SwiftyJSON to convert let… continue reading.

Detecting OpenWhisk web actions

I've already written about OpenWhisk web actions and how they allow you to send a status code and HTTP headers to the client by returning a dictionary with the keys status, headers and body from your main() method: func main(args: [String:Any]) -> [String:Any] { return [ "body": "Hello world", "statusCode": 200, "headers": [ "Content-Type": "text/xml", ], ] } If this test action is in the default namespace, then we create it with wsk action update… continue reading.

Calling an OpenWhisk action in Swift

As OpenWhisk is a Functions as a Service system, it makes sense to create actions that do one thing and call other actions when they want other work done. As an example, in DrinksChooser, the choose action calls the incrementDrinkCount action which increments the count of the recommended drink in Redis. This way, choose doesn't have to know anything about Redis as that's not its job. In OpenWhisk's Swift environment, there's the Whisk.invoke() method to… continue reading.

Passing secrets to your OpenWhisk action

There is only one way to pass data into your OpenWhisk action: parameters. Your function receives a dictionary of parameters and returns one. Let's explore how you can set these parameters. Parameters passed to the action You can see this by creating this action: test.swift func main(args: [String:Any]) -> [String:Any] { return args } Add the action to OpenWhisk with: wsk action update params params.swift -a web-export true and test: $ wsk action invoke -b… continue reading.

Quick tip: OpenWhisk autocompletion

I've just discovered how to enable Bash autocompletion for the wsk command line tool! $ cd /usr/local/bin $ wsk sdk install bashauto This will create a file called wsk_cli_bash_completion.sh in your /usr/local/bin directory. Now, source this file within your .bash_profile or equivalent: $ echo -e "\n# OpenWhisk autocompletion\nsource ~/bin/wsk_cli_bash_completion.sh" >> ~/.bash_profile Start a new terminal window, (or source ~/.bash_profile in your current one) and you can now press the tab key after typing wsk to… continue reading.