This topic describes the steps and command format for using fun local invoke commands to run event functions in different languages.

Notice The content described in this article will no longer be maintained later. If your Function service resources are managed by Funcraft, we recommend that you migrate the resources to Serverless Devs.

For more information about how to migrate Function Compute-related resources from Funcraft to Serverless Devs, see Migrate resources from Funcraft to Serverless Devs.

For more information about Serverless Devs, see Overview.

For more information about how to use Serverless Devs to debug functions, see Debug Functions and Remote debug Using s Local Related Commands.

We apologize for any inconvenience caused.

Command syntax

There are several ways to run the command format of local event functions.
  • Run the function by using the function name.
    fun local invoke <your function>
  • Run the service name /function name.
    fun local invoke <your service>/<your function>
Note
  • You can directly use the fun local invoke to run the function. You can use the Service Name /Function Name method to match the function.
  • If the template.yml contains multiple services and multiple services contain functions with the same name, if the function name is called, the Funcraft tool will only run the first matching function.

Node.js and Python functions

Node.js and Python functions run in the same way. The following example describes how to run a Node.js function by using the function name demo and application template event-nodejs8.

  1. Run the following command to build a function:
    fun init event-nodejs8 -o ./demo
  2. Run the function in the target directory with the following command.
    • Run the function by Function Name.
      fun local invoke demo
    • Run the function by using Service Name /Function Name.
      fun local invoke demo/demo

You can also use -d parameters to debug Node.js and Python functions. For more information, see Debug Node.js and Python functions.

Java functions

The following example describes how to run a Java function by using the function name demo and application template event-java8.

  1. Run the following command to build a function:
    fun init event-java8 -o ./demo
  2. Run the following command to compile the function:
    fun build demo
    Note Since Java is different from interpreted languages, you need to compile before running functions. For more information about building code packages, see Run the fun build command to build a code package.
  3. Run the function in the target directory with the following command.
    • Run the function by Function Name.
      fun local invoke demo
    • Run the function by using Service Name /Function Name.
      fun local invoke demo/demo

You can also use -d parameters to debug Java functions. For more information, see Debug Java functions.

PHP functions

The following example describes how to run a PHP function by using the function name demo and application template event-php7.2.

  1. Run the following command to build a function:
    fun init event-php7.2 -o ./demo
  2. Run the function in the target directory with the following command.
    • Run the function by Function Name.
      fun local invoke demo
    • Run the function by using Service Name /Function Name.
      fun local invoke demo/demo

You can also debug PHP functions with -d parameters. For more information, see Debug PHP functions.