Chapter 3. Working with Actions

In the first chapter, I referred to serverless as Function as a Service (FaaS). Within OpenWhisk, actions are how we refer to those functions. Everything you build will begin with actions, so understanding how to build and use them is fundamental to being a serverless developer on the OpenWhisk platform. I’ll begin by covering the fundamentals of how actions should be built. You should think of these as guideliness, not hard and fast rules. I’ll then switch to the actual rules you have to follow.

This chapter will focus on working with actions via the CLI. While this covers how developers interact with OpenWhisk, it certainly isn’t how the public will use it. The next chapter will demonstrate how you can take these actions and make them available to the public.

The Fundamentals of OpenWhisk Actions

As previously described, what follows are the fundamentals (or principles) of how you should build your actions. These are guidelines you should follow but are not done at the code level. Consider them best practices, but note that you may bend these best practices from time to time.

First off, actions are typically small pieces of code. However, “small” is, of course, relative. It may mean 20 lines of code, or it may mean 200. But in general, if you find yourself working on a file that’s getting larger and larger, it may make sense to break it up into smaller actions.

Next, actions are atomic and stateless, meaning they run, do their stuff, and then ...

Get Developing Serverless Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.