We will login through IBM Cloud CLI and deploy a function following the as follows: steps. Exact outputs for these steps may differ slightly when you run these commands for the first time and further executions.
- Execute ibmcloud login and enter the username and password as follows:
ibmcloud login
You should see an output as follows with further prompts:
- Enter the option number for us-south
You should see further response as:
If you have not updated credit card and using a lite account, you may see a different screen with lesser options.
- Run:
ibmcloud target –cf
There should be an organization with your email address. Select it.
- Install the cloud functions plug-in:
ibmcloud plugin install cloud-functions
- Create a file name hello.js with following contents:
function main(params) {
var name = params.name || 'World';
return {payload: 'Hello, ' + name + '!'};
}
I have used Node.js code as provided in IBM samples.
- Create hello action:
ibmcloud fn action create hello hello.js
- Invoke the function without passing parameters:
ibmcloud fn action invoke helloworld --blocking --result
You should see an output, as follows:
- Invoke action with parameters:
ibmcloud fn action invoke hello --blocking --result --param name Heartin