Compute Services

Simplify binding your IBM Cloud services to serverless Functions

Share this post:


Introducing a new command for the IBM Cloud Functions CLI plug-in to make it easier to configure your actions to have access to your IBM Cloud service credentials.  The new service command is a convenient way to make your IBM Cloud service credentials available to your Cloud Functions code at run time.  The new command helps with a form of secret management for your IBM Cloud services within the context of IBM Cloud Functions.

Introducing the bx wsk service CLI command


The bx wsk service bind retrieves the specified service’s credentials and “binds” the requested service credentials to your Cloud Functions action as a new parameter.  Once the credentials are “bound”, you can leverage them like any other parameter that is defined for that action.

The new service command is not to be confused with the cf bind-service command that is available in Cloud Foundry.  It is simply an automated way to create a new parameter on your existing action that contains service credentials.

How the service command differs from the existing package refresh command

If you are familiar with IBM Cloud Functions packages, you might wonder what the difference between bx wsk service bind and bx wsk package refresh is.  The package refresh command only updates credentials for very specific IBM provided service for which Cloud Functions provides custom integrations.  For example, Cloudant, MessageHub and the Weather services are supported.

The service bind command is more flexible and allows you to bind any IBM Cloud service to any action that is defined in IBM Cloud Functions. The only caveat is that you must have credentials defined for the service that you want to bind.


To obtain the credentials from your Watson Conversation service, and make it available to your “TravelAdvisor” action, run the following command:

bx wsk service bind conversation TravelAdvisor

To see what is currently bound and where it came from, you can run the following command:

bx wsk action get TravelAdvisor

The Watson conversation service credentials are now available to the TravelAdvisor action as a parameter named __bx_creds as shown in the following code.  For example, pretend the TravelAdvisor action has the following code:

function main({
__bx_creds: {conversation:{url}},
__bx_creds: {conversation:{username}},
__bx_creds: {conversation:{password}}
console.log("Use the Watson Conversation API with credentials:", url, username, password);

If you run bx wsk action invoke TravelAdvisor -r, you might see something like the following output:

{ }

What gives?  Well the output was printed to standard out, and not returned as part of the response.  To view the log, you can check the last activation with the command bx wsk activation get -l :

ok: got activation

"namespace": "",
"name": "TravelAdvisor",
"version": "0.0.3",
"subject": "",
"activationId": "b96d80816f0349fbad80816f03e9fbdf",
"start": 1509462891021,
"end": 1509462891087,
"duration": 66,
"response": {
"status": "success",
"statusCode": 0,
"success": true,
"result": {}
"logs": [
"2017-10-31T15:14:51.08598289Z stdout: Use the Watson Conversation 
API with credentials: <watson-url> <watson-username> <watson-password>"
"annotations": [
"key": "limits",
"value": {
"logs": 10,
"memory": 256,
"timeout": 60000
"key": "path",
"value": ""
"key": "kind",
"value": "nodejs:6"
"publish": false

If you no longer wish to have this binding reflected in the action, as you no longer use this service, you can remove it using the unbind command:

bx wsk service unbind conversation TravelAdvisor

If you rerun your TravelAdvisor action again (bx wsk action invoke TravelAdvisor) after your credentials are unbound, you might see something like the following output:

"error": "An error has occurred: TypeError: Cannot match against 'undefined' or 'null'."

Remember to always run the bx wsk service command after you set up all your other default parameters.If you run bx wsk action update to modify parameters, the credentials binding is removed along with any other parameters not included in the action update. If this happens, remember to run bx wsk service bind again.

For more information about this new feature, take a look at the documentation for the Cloud Functions plug-in –

Get started with IBM Cloud Functions with your Free account.

Add Comment
No Comments

Leave a Reply

Your email address will not be published.Required fields are marked *

More DevOps Stories

Utilizing Multi-Container Functionality with IBM Cloud Developer Tools CLI

The latest update to the IBM Cloud Developer Tools CLI, version 1.1.0, provides support for applications that use multiple containers which are configured using Docker Compose yaml files. These files contain necessary information about the containers you wish to run. With Docker installed, you already have the requisite dependency to run multiple containers locally.

Continue reading

IBM Cloud Log Analysis – Now Available in Germany and Sydney!

Starting today, IBM Cloud Log Analysis expands its availability from US-South to include the Germany and Sydney regions. Empower your DevOps team with IBM Cloud Log Analysis. Gain insights into your environment to quickly detect, diagnose, and identify issues. Keep your log data and your application workloads safeguarded on a centralized cloud class economical storage solution. Visit us in the IBM Cloud Catalog.

Continue reading

Speed deployment on Kubernetes with Helm Chart – Quick YAML example from scratch

Are you working with Kubernetes, with all the recent supporting releases on IBM Cloud Private, the IBM Bluemix Container Service on IBM Cloud Platform, or elsewhere? Are you in the middle of containerizing workloads across your portfolio? Have you adopted Kubernetes and looking to speed up deployment and reuse? This post is a learn-by-doing example that introduces you to Helm and Helm Charts.

Continue reading