I am trying to create an openwhisk action that uses the minio server. In order to do that I have to package my action as a nodeJs module cause minio is not supported by openwhisk. My index.js file is the following:
function myAction(){
const minio = require("minio")
const minioClient = new minio.Client({
endPoint: 'myIP',
port: 9000,
secure: false,
accessKey: '###########',
secretKey: '###########'
});
minioClient.listBuckets(function(err, buckets) {
if (err) return console.log(err)
return {payload: buckets}
})
}
exports.main = myAction;
When I am invoking this action I get {}. Do you have any ideas why is this happening? Any suggestions of how can I solve it?
An OpenWhisk action expects you to return a Promise, if you're doing something asynchronously.
In your case, you'll need to construct a promise which is resolved once the listBuckets
method is done (generally this means: You need to resolve it in the callback).
function myAction(){
const minio = require("minio")
const minioClient = new minio.Client({
endPoint: 'myIP',
port: 9000,
secure: false,
accessKey: '###########',
secretKey: '###########'
});
return new Promise(function(resolve, reject) {
minioClient.listBuckets(function(err, buckets) {
if (err) {
reject(err);
} else {
resolve({payload: buckets});
}
});
});
}
exports.main = myAction;
(Untested code).