Packages
Browsing public packages
IBM Cloud Functions comes pre-installed with a number of public packages, which include trigger feeds used to register triggers with event sources.
Actions in public packages can be used by anyone, the caller pays the invocation cost.
Using ibmcloud fn
CLI you can get a list of packages in a namespace, list the entities in a package and get a description of the entities within a package.
Get a list of packages in the
/whisk.system
namespace.ibmcloud fn package list /whisk.system
packages /whisk.system/alarms shared /whisk.system/cloudant shared /whisk.system/combinators shared /whisk.system/cos shared /whisk.system/github shared /whisk.system/messaging shared /whisk.system/pushnotifications shared /whisk.system/samples shared /whisk.system/slack shared /whisk.system/utils shared /whisk.system/watson-speechToText shared /whisk.system/watson-textToSpeech shared /whisk.system/watson-translator shared /whisk.system/weather shared /whisk.system/websocket shared
Some Packages have Actions that are also Feeds, that is they implement the Feed interface and know how to manage (connect) to external services that are event sources.
Get a list of entities in the
/whisk.system/cloudant
package.ibmcloud fn package get --summary /whisk.system/cloudant
package /whisk.system/cloudant: Cloudant database service (parameters: *apihost, *bluemixServiceName, *dbname, *host, overwrite, *password, *username) action /whisk.system/cloudant/read: Read document from database (parameters: dbname, id, params) action /whisk.system/cloudant/write: Write document in database (parameters: dbname, doc) ... feed /whisk.system/cloudant/changes: Database change feed (parameters: dbname, filter, query_params)
This output shows that the Cloudant package provides many actions including
read
andwrite
, and a trigger feed calledchanges
. Thechanges
feed causes triggers to be fired when documents are added to the specified Cloudant database.The Cloudant package also defines the parameters
username
,password
,host
, anddbname
. These parameters must be specified for the actions and feeds to be meaningful. The parameters allow the actions to operate on a specific Cloudant account.
Invoking actions in a package
You can invoke actions in a package, just as with other actions. The next few steps show how to invoke the greeting
action in the /whisk.system/samples
package with different parameters.
Invoke the greeting action without any parameters.
ibmcloud fn action invoke --result /whisk.system/samples/greeting
{ "payload": "Hello, stranger from somewhere!" }
Invoke the action with parameters.
ibmcloud fn action invoke --result /whisk.system/samples/greeting --param name Arya --param place Winterfell
{ "payload": "Hello, Arya from Winterfell!" }
Notice that the output uses the
name
andplace
parameters that were passed to the action.
Creating and using package bindings
Although you can use the entities in a package directly, you might find yourself passing the same parameters to the action every time. You can avoid this by binding to a package and specifying default parameters. These parameters are inherited by the actions in the package.
Bind to the
/whisk.system/samples
package and set a defaultpayload
parameter value.ibmcloud fn package bind /whisk.system/samples mySamples --param payload "The quick brown fox"
ok: created binding mySamples
Get a description of the package binding.
ibmcloud fn package get --summary mySamples
package /namespace/mySamples: Returns a result based on parameter place (parameters: *place) action /namespace/mySamples/helloWorld: Demonstrates logging facilities (parameters: payload) action /namespace/mySamples/greeting: Returns a friendly greeting (parameters: name, place) action /namespace/mySamples/curl: Curl a host url (parameters: payload) action /namespace/mySamples/wordCount: Count words in a string (parameters: payload)
Notice that all the actions in the
/whisk.system/samples
package are available in themySamples
package binding.Invoke an action in the package binding
ibmcloud fn action invoke --result mySamples/wordCount
{ "count": 4 }
Invoke an action and overwrite the default parameter value.
ibmcloud fn action invoke --result mySamples/wordCount --param payload "Picks up the rice in the church where a wedding has been"
{ "count": 12 }
Sharing packages
Make the package public...
Share the package with all users:
ibmcloud fn package update custom --shared yes
Last updated
Was this helpful?