Leonard Saers
Leonard Saers

Reputation: 663

Fail to invoke step function using serverless framework ("stepf" is not a valid sub command)

After the installing of the serverless step function plugin

npm install -g serverless
npm install -g serverless-step-functions

... and successfully deploy the step function through

serverless deploy

... Then I try to run: serverless invoke stepf

serverless invoke stepf --name ${sf} --data '${OUTPUT}' 

  Serverless Error ---------------------------------------
 
  "stepf" is not a valid sub command. Run "serverless invoke" to see a more helpful error message for this command.

... And I get "stepf" is not a valid sub command

Why can't use the functionality from the serverless-step-functions plugin to invoke a step function?

The invoke command is described on the serverless-step-functions git-hub page: https://github.com/serverless-operations/serverless-step-functions#invoke

The used version of the plugin serverless-step-functions is 2.21.1

Edit

An important piece of information is that the invoke command was executed from a folder that did not contain a serverless.yml file

Upvotes: 2

Views: 891

Answers (1)

Leonard Saers
Leonard Saers

Reputation: 663

The invoke command was executed from a directory which did not have a serverless.yml file.

Adding this minimal yaml file activated the plugin

service: some-step-function
provider:
  name: aws
  region: eu-north-1
  runtime: java11
  timeout: 30

plugins:
  - serverless-step-functions

But in order to run:

serverless invoke stepf --name ${sf} --data '${input}' 

... the name parameter in invoke must be the name described in the serverless.yml file.

In the example below, the correct value for the name parameter is aStateMachine. I first did the uncorrected assumption that the name was the same as the name parameter under the state machine.

service: some-step-function
provider:
  name: aws
  region: eu-north-1
  runtime: java11
  timeout: 30

...

stepFunctions:
  stateMachines:
    aStateMachine:
      name: thisIsNotTheName

plugins:
  - serverless-step-functions

Amusing that you are in the same directory as the above serverless.yml file. A working invoke to a step function could look something like:

serverless invoke stepf --name aStateMachine --data '{}' 

The above example explain the error message in the question. It's however much more convenient to build a solution where the invoke command is executed from the directory where you have the serverless.yml file.

Upvotes: 4

Related Questions