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.

Product Marketing Manager - Cloud Computing

Jesse Alva

Developer - Mobile Innovation Lab

Add Comment
No Comments

Leave a Reply

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

More DevOps stories

Process large data sets at massive scale with PyWren over IBM Cloud Functions

(Ed.–Josep Sampé–Universitat Rovira i Virgili–co-authored this post.) Let’s say you write a function in Python to process and analyze some data. You successfully test the function using a small amount of data and now you want to run the function as a serverless action at massive scale, with parallelism, against terabytes of data. What options do you have? Obviously, […]

Continue reading

Combine organizational transformation and IBM Cloud infrastructure for a successful AI journey

With our recent cloud infrastructure and Deep-Learning-as-a-Service (DLaaS) announcements, IBM Cloud is a key contributor to the push towards AI. We’ve delivered a comprehensive suite of AI tools, high performance bare metal servers, and NVIDIA® GPUs that enables companies of all sizes to analyze complex unstructured data faster, more thoroughly and accurately, and at a far less cost than ever before.

Continue reading

Scale security while innovating microservices fast

CISOs are notoriously risk-averse and compliance-focused, providing policies for IT and App Dev to enforce. In contrast, serving business outcomes, app dev leaders want to eliminate DevOps friction wherever possible in continuous integration and development of applications within a cloud native, microservices architecture. What approach satisfies those conflicting demands while accomplishing the end goal: scale security?

Continue reading