Skip to content

Instantly share code, notes, and snippets.

@upkarlidder
Last active April 9, 2020 20:34
Show Gist options
  • Save upkarlidder/897f6c3e3ce313736cdbacde9acdb17a to your computer and use it in GitHub Desktop.
Save upkarlidder/897f6c3e3ce313736cdbacde9acdb17a to your computer and use it in GitHub Desktop.
#
#
# main() will be run when you invoke this action
#
# @param Cloud Functions actions accept a single parameter, which must be a JSON object.
#
# @return The output of this action, which must be a JSON object.
#
#
import sys
def main(dict):
if 'name' in dict:
return { 'message': 'Hello ' + dict['name'] }
else:
return { 'message': 'Hello world' }
function main(params) {
return new Promise((resolve, reject) => {
// long running operation
console.log('params start');
console.log(params);
console.log('params end');
if (params && params.name) {
console.log(`hello ${params.name}`);
resolve({ msg: `hello ${params.name}` });
} else {
console.log('hello world');
reject({ msg: 'hello world' });
}
})
}
function main(params) {
if(params && params.name) {
console.log(`hello ${params.name}`);
return {msg: `hello ${params.name}`};
} else {
console.log('hello world');
return {msg: 'hello world'};
}
}
@upkarlidder
Copy link
Author

upkarlidder commented Apr 9, 2020

Commands

  1. ibmcloud fn action create helloworldcfe index.js
  2. ibmcloud fn action invoke helloworldcfe
  3. ibmcloud fn activation get {activation id from 2}

Promise version

❯ ibmcloud fn action update helloworldcfe index.js
❯ ibmcloud fn action update helloworldcfe index.js
ok: updated action helloworldcfe
❯ ibmcloud fn action invoke helloworldcfe -r
{
    "error": {
        "msg": "hello world"
    }
}
❯ ibmcloud fn action invoke helloworldcfe -r -p name "upkar lidder"
{
    "msg": "hello upkar lidder"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment