ESP vs IBM Cloud Functions

IBM Cloud Functions are IBM Cloud’s equivalent to AWS Lambda. Like Lambda, IBM Cloud Functions let you write custom functions and expose them via an HTTP interface through either IBM Cloud Function’s minimal HTTP configuration or IBM API Connect for more sophisticated use cases. Express Serverless Platform offers a similar stack that lets you write Node.js APIs and expose those APIs through Express Gateway without vendor lock in. In this article, I’ll walk through setting up a rudimentary Node.js function in both Express Serverless Platform and IBM Cloud, and discuss the tradeoffs of using one over the other.


IBM Cloud

Go to IBM’s OpenWhisk landing page and log in. IBM Cloud is the new name for what used to be called Bluemix, so don’t be surprised by the URL. OpenWhisk is an Apache open source project that provides the backbone for IBM Cloud Functions.


Once you’ve logged in, click on the “Actions” tab on the left and then click “Create.”



For this simple example, click on “Quickstart Templates” to get a list of ready-made “actions.” In OpenWhisk, an action is just another name for a function.



Select the “Hello World” function template.



The next step asks you for a package name, a runtime, and the actual code. A package is just a container for one or more cloud functions, potentially with shared configuration. IBM Cloud will fill in the form with package name “hello-world”, Node.js 8 as the runtime, and a simple “Hello World” function as the code, so you shouldn’t need to make any changes, just hit the “Deploy” button.



Great, now you have your first cloud function. You can execute the function, but it is not accessible via HTTP. Click the “Endpoints” tab on the left to create an endpoint for this function.



Now, click the “Enable as Web Action” checkbox to expose this action via REST API. A web action has a couple special properties as opposed to a regular action. First, a web action _must_ return an object that is serializable into JSON, or a promise that resolves to such an object. Second, if a web action returns an object that has a headers, statusCode or body property, OpenWhisk will use those properties to structure the HTTP response, rather than just stringifying the resulting JSON object.



Once you’ve made your action into a web action, you should be able to access it via REST API. Click the copy icon in the “HTTP Method” panel to copy the URL for your function. You should then be able to use curl to access your function via HTTP. Keep in mind IBM Cloud Functions do not have any authentication by default, so you don’t need any API key.



Running curl on the URL will then execute your function and give you the result.


$ curl
  "greeting": "Hello stranger!"

Express Serverless Platform and Express Gateway

In Express Serverless Platform, first create a new function and name it ‘myfunction’:



Node.js functions in Express Serverless Platform have the same function signature as native Node.js HTTP request listeners. The function to print ‘Hello, world!’ with Express Serverless Platform is shown below. Note that the exported function must have the same name as the function name you assigned in the Express Serverless Platform GUI.


module.exports = {
  myfunction (req, res) {
    res.end('Hello, world!');




Note that this function does not have to create an actual HTTP server. Express Serverless Platform handles creating a server for you, so you can write “serverless” functions without having to actually write an express application. You do still get access to the Node.js HTTP response, so you can set HTTP headers and set the HTTP status code.

From the menu on the left, add a new gateway. This will add an Express Gateway instance to your project.



Click the plus icon next to “Policies” to add a policy to the default Express Gateway pipeline. In Express Gateway, a pipeline is a sequence of policies for handling a request. Add an empty ‘proxy’ pipeline.



Drag a line from your gateway to your function, and Express Serverless Platform will automatically connect your proxy policy to your function.



Express Serverless Platform will also create a function endpoint for you. Keep the “paths” for your function endpoint empty for now. Click on the “settings” icon to find the publicly accessible URL for your Express Serverless Platform project.



Running curl on the URL will now run your custom function and give you the “Hello, world!” text.


$ curl
Hello, World!

Moving On

The combination of Express Serverless Platform and Express Gateway is a great alternative to IBM Cloud Functions if you’re looking to avoid vendor lock-in. IBM Cloud Functions are built on OpenWhisk, so in theory you should be able to migrate your IBM Cloud Functions deployment onto OpenWhisk, but IBM doesn’t provide any documentation on how to do that. On the other hand, Express Serverless Platform scaffolds out an app for you and stores it in a git repo that you can clone. That enables you to run your app locally or on any cloud provider. Express Serverless Platform does automatically host your app for you, but that isn’t your only option. IBM Cloud is appealing because IBM is a well-established company, but using IBM Cloud Functions means you must run your code on IBM Cloud and manage your API using IBM API Connect.


We’ve done up a detailed comparison analysis on features, pricing and more between Express Serverless Platform running on IBM compared to IBM Cloud Functions, which is available for download from our Resources page.


Additionally, if you’re interested in more of these topics, join the live discussion on twitter @lunchbadger or @express_gateway.


Share Tweet Link