0

I have an IBM Cloud Function (OpenWhisk) that invokes a Watson Conversation Service. We are using JAVA The documentation of the JAVA SDK (https://github.com/watson-developer-cloud/java-sdk ) suggests that the credentials would be picked up from the binding.

When I list the bindig I get this:

>bx wsk action get talksmall parameters
ok: got action talksmall, displaying field parameters
[
    {
        "key": "__bx_creds",
        "value": {
            "conversation": {
                "credentials": "Credentials-SmallTalk",
                "instance": "<INSTANCE>",
                "password": "<PASSWORD>",
                "url": "https://gateway.watsonplatform.net/conversation/api",
                "username": "<USERNAME>"
            }
        }
    }
]

But when I use the SDK like this:

Conversation conversationService = new Conversation(Conversation.VERSION_DATE_2017_05_26);

I get an error

{
  "error": "An error has occured while invoking the action (see logs for details): java.lang.IllegalArgumentException: apiKey or username and password were not specified"
}

When I add the line:

conversationService.setUsernameAndPassword(userName, password);

It works. Maybe the VCAP_Service way of binding does not work with Cloud Functions ? The Cloud Function runs in the same IBM Cloud organization and space.

mpjjonker
  • 917
  • 1
  • 6
  • 28

1 Answers1

2

I opened an issue against the SDK documentation which talks about "running in Bluemix". IBM Cloud offers infrastructure, OpenWhisk / Cloud Functions, Cloud Foundry and more. Bluemix originated from Cloud Foundry and the automatic binding via VCAP_SERVICE is a Cloud Foundry feature.

From my experience with using IBM Cloud Functions with Python and Node.js you need to call the API functions to set credentials explicitly. With the feature of service binding you can easily make credentials of provisioned services available to the context within IBM Cloud Functions as successfully shown in your code above.

data_henrik
  • 16,724
  • 2
  • 28
  • 49