Sequences

IBM Cloud Functions supports a kind of action called a "sequence". Sequence actions are created using a list of existing actions. When the sequence action is invoked, each action in executed in order of the action parameter list. Input parameters are passed to the first action in the sequence. Output from each function in the sequence is passed as the input to the next function and so on. The output from the last action in the sequence is returned as the response result.

Let's look at an example of using sequences.

  1. Create the file (funcs.js) with the following contents:

     function split(params) {
       var text = params.text || ""
       var words = text.split(' ')
       return { words: words }
     }
    
     function reverse(params) {
       var words = params.words || []
       var reversed = words.map(word => word.split("").reverse().join(""))
       return { words: reversed }
     }
    
     function join(params) {
       var words = params.words || []
       var text = words.join(' ')
       return { text: text }
     }
  2. Create the following three actions:

     ibmcloud fn action create split funcs.js --main split
     ibmcloud fn action create reverse funcs.js --main reverse
     ibmcloud fn action create join funcs.js --main join

Creating sequence actions

Now, let's see them all work together as an action sequence...

  1. Create the following action sequence.

    ibmcloud fn action create reverse_words --sequence split,reverse,join
  2. Test out the action sequence.

    ibmcloud fn action invoke reverse_words --result --param text "hello world"
    {
       "text": "olleh dlrow"
    }
  3. List the last few activations

    ibmcloud fn activation list -l 4

Last updated

Was this helpful?