Serverless: Serverless error property not found

Viewed 362

I have this serverless.yaml

service: BATCH-lambda-f
provider:
  name: aws
  name: serverless-fac-${opt:stage,self:provider.stage}
runtime: nodejs12.x
stage: develop
custom:
   credentials: ${file(./scripts/myScript.js)}

in my myScript.js file I want to access the serverless functions in this way:

module.exports = async (serverless) => {
    serverless.cli.log('example');
    const stage = serverless.getProvider('aws').getStage();
    console.log(stage);
    .....
    .....
}

I get this error:

Serverless Error

Cannot resolve serverless.yaml: Variables resolution errored with:
Cannot resolve variable at "custom.credentials": Cannot resolve "myScript.js": Returned JS function errored with: TypeError: Cannot read property 'log' of undefined
1 Answers

The error clearly says that Cannot read property 'log' of undefined which means you are trying to access "cli" object from the "serverless" object passed to the function which does not exist basically. Try to cosole log serverless and check its value.

Related