Issue: Openwhisk

Error:

{

    "error": "An error has occurred: Error: Invalid constructor options. Missing api_key parameter or token plugin."

}

Steps to reproduce:

1. create js program proxy.js

var openwhisk = require('openwhisk');

function main(params) {
        if(params.password !== "secret") {
                throw new Error("Passoword incorrect");
        } 
        var ow = openwhisk(); // not passing any value to constructor will result in error.
        return {"status":"Logged in"};
}

2. Deploy: 
wsk action create proxy proxy.js

3. invoke
wsk action invoke proxy -p password secret --result

Solution:

1. install openwhisk with npm package manager
npm install openwhisk

2. pass parameter to openwhisk():                
var openwhisk = require('openwhisk');

function main(params) {
        if(params.password !== "secret") {
                throw new Error("Passoword incorrect");
        } 

        options={apihost: 'openwhisk.ng.bluemix.net', api_key:'...'};

        var ow = openwhisk(options);
        // return ow.actions.invoke({name:"hello", blocking:true, resutl:true, param :params});
        return {"status":"Logged in"};
}


Error 2: 

"error": {
            "code": "3dX9s8a1GhideL4Y7vKgFsFeluSZMEPV",
            "error": "The supplied authentication is invalid"
        }

Steps to reproduce:

1. Save the above solved program and run.

solution:


1. program hello.js and create action hello
2. program proxy.js and create action proxy
3. pass the auth.json while inovking proxy.js

The authentication is required for local env.

Comments

Popular posts from this blog