Relative Links with IBM Cloud API Gateway

I work quite a bit with serverless tech, particularly on IBM Cloud since I work there. At the moment I'm building a microservice using web actions. When a user creates data with a POST request, I want to redirect them to the URL of the new thing they created - but for that I need to know the URL that it was accessed with. This is a relatively new feature on API Gateway so here's a quick howto for grabbing that URL in both JavaScript and PHP. Continue reading

React to Database Changes with OpenWhisk Actions

One of the best features of CouchDB is its change feed which allows us to get a feed of the changes happening on our database. It's also possible to have a serverless function (examples are for IBM Cloud Functions but should also work for Apache OpenWhisk) that fires in response to activity on that change feed. I have a database of events that I want to react to when they happen, but the change feed doesn't include the actual document that was added - but you can add one of the built-in functions to a sequence to make that happen. This post will show how to achieve this by wiring up a built-in action to fetch the document with another action of our own that then handles the data. Continue reading

Handle Webhooks with Serverless PHP

Did you know you can serverless with PHP? OK, so serverless is clearly not a verb, but since I love serverless tech and have also loved PHP for longer than I'm going to admit (the dates of the earliest posts on this blog might serve as a clue), using these technologies together is definitely my idea of a good time.

I included an example of a serverless endpoint to receive incoming webhooks in my talk at PHPUK last week and I got a few questions about it so I thought I'd share that example in written form. Continue reading

Deploying OpenWhisk Actions With Dependencies

I mostly use OpenWhisk with NodeJS (which is lucky for me, it's the best supported of the languages and default for the documentation examples!) and while there are a bunch of npm modules already installed on OpenWhisk, sometimes there will be others that you also want to include. Alternatively or additionally, you might also want to deploy your package.json since this can specify the entry point if it's not index.js which is the default.

Continue reading

Package Parameters in OpenWhisk

I love OpenWhisk but I struggled a little to get the parameters attached in a sane way for a while so I am capturing my notes here for future reference! Parameters can be attached to actions or packages; I tend to break my actions down really small and pass data into them, while preferring to set parameters on the package that the actions belong to. Continue reading

One OpenWhisk Action Calls Another

Working with openwhisk, it's easy to create many isolated actions and build them up into sequences; the output of one action is passed to the next action in the sequence. In my case, I wanted one action to spawn potentially many other actions. I had to look up how to do it and here it is so I can look it up more quickly next time! Continue reading

Alexa Project Name Generator on OpenWhisk

I'm having lots of fun with my Amazon echo and echo dots, creating skills for them. Initially I used Amazon's lambda platform since that's a very easy way to get started - but I'm an advocate for IBM and was looking for an excuse to play with OpenWhisk (an open source serverless offering that Bluemix has a hosted version of) anyway so this was a great opportunity!

Configuring Skills

There are a bunch of good resources around for setting up skills, picking the name, configuring the "invocation" which is what to say to make the code happen, and so on. I'll skip this section and instead just share a couple of tutorials that I rely on a lot:

Once your skill is configured, it's time to write the code (note: UK users need to pick English (UK) and not English (US) as otherwise your skill will mysteriously fail in your home region. Guess how I learned that??) Continue reading

One-Line Command For Newest OpenWhisk Logs

One of my current project uses OpenWhisk, which is an open source serverless technology stack. IBM has it on their Bluemix platform, and since I work there, I get to play with it as much as I like! One thing that did seem clunky is that it takes more than one step to get the logs of the most recent function run via commandline - first you list the activations, then you request the logs of the activation you're interested in. Of course, when you're developing, that's usually the most recent one so here's my shortcut for that:

wsk activation list -l1 | tail -n1 | cut -d ' ' -f1 | xargs wsk activation logs

From left to right, sections separated by the pipe | character, this is what happens:

  • get a list of activations, limited to just one activation (it sorts the newest one first by default)
  • grab only the last line of that output (there's some extra titles and stuff in there)
  • use the `cut` command with the space character as a field delimiter, and use only the first field (this gets the ID of the activation)
  • get the logs of that activation

Of course it's wrapped up in a script so I just run that from the commandline and check where I went wrong this time ...