DEV Community

Play Button Pause Button
Matt Hamilton
Matt Hamilton

Posted on

Intro to IBM Cloud Functions

IBM Cloud Functions are a "serverless" technology based on Apache Openwhisk hosted by IBM. They allow you to write code and deploy it without having to worry about hosting, operating systems.

Above is the first part of a series of live coding sessions on Twitch I've done exploring IBM Cloud functions and showing some simple examples.

Also available on Cinnamon at: https://www.cinnamon.video/watch?v=329436575563777372

Session recap

To start with you need an account on IBM Cloud. You can get a free account by signing up here.

You can either manage the Cloud functions through the IBM Cloud web portal, or you can use the command line interface (CLI). To install the CLI and Cloud Functions plugin, details are here: https://cloud.ibm.com/functions/learn/cli

There are four main constructs in Cloud Functions:

  • Actions
  • Sequences
  • Triggers -Rules

In this session, we mainly covered actions, which is where the code lives. IBM Cloud Functions is based on Apache Openwhisk and offers a number of different runtimes: JS/NodeJS, Swift, Java, Python, Ruby, Go, PHP, .NET, Any language (Docker).

Openwhisk runtimes

Some simple examples of creating, updating, invoking and deleting an action in IBM Cloud Functions

A simple hello world function:

def main(args):
    name = args.get("name", "unknown")
    return {"message": f"Hello {name}!"}
Enter fullscreen mode Exit fullscreen mode

Create an action:

% ic fn action create hello hello.py
ok: created action hello
Enter fullscreen mode Exit fullscreen mode

List actions:

% ic fn action list                             
actions
/Matthew.Hamilton1@ibm.com_dev/hello                                   private python:3.7
Enter fullscreen mode Exit fullscreen mode

Invoke a function:

% ic fn action invoke hello -r
{
    "message": "Hello unknown!"
}
Enter fullscreen mode Exit fullscreen mode

Update a function:

% ic fn action update hello hello.py
ok: updated action hello
Enter fullscreen mode Exit fullscreen mode

Delete a function:

% ic fn action delete hello         
ok: deleted action hello
Enter fullscreen mode Exit fullscreen mode

As usual all the code and examples here can be found in my Github repository for the show:

GitHub logo IBMDeveloperUK / ML-For-Everyone

Resources, notebooks, assets for ML for Everyone Twitch stream

ML for Everyone

ML For everyone is a live show broadcast on the IBM Developer Twitch channel every week at 2pm UK time.

The show is presented by Matt Hamilton and focusses on topics in and around machine learning for developers, with the odd smattering of random Python topics now and then.

Preview of show

Past shows

I hope you enjoyed the video, if you want to catch them live, I stream each week at 2pm UK time on the IBM Developer Twitch channel:

https://developer.ibm.com/livestream/

Oldest comments (0)