This topic describes function-related commands in the FC-API component.

Prerequisites

Before you begin, make sure that the following operations are complete:

Create a function

Command syntax:
s cli fc-api createFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --description <description> --code <codefile> --customContainerConfig <customContainerConfig>  --handler <functionhandler> --runtime <runtime> --initializationTimeout <initializationTimeout> --initializer ----memorySize <momorysize> ----timeout <timeout> --caPort <caport>
Parameters:
  • --region string: the ID of the region where the resource is deployed.
  • --access string: the alias of the key used.
  • --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
  • --serviceName string: the name of the service.
  • --functionName string: the name of the function.
  • --code string: the ZIP code file.
  • --customContainerConfig string: the configuration of the custom container runtime. After you configure the custom container runtime, Function Compute can execute functions in a container created from a custom image.
  • --description string: the description of the function.
  • --handler string: the handler of the function. The handler is in the format of "file name.function name". For example, hello_world.handler indicates that the handler is the handler function in the hello_world.js file.
  • --initializationTimeout number: the timeout period for the execution of the initializer function.
  • --initializer string: the initializer function.
  • --memorySize number: the memory size for the function.
  • --runtime string: the runtime environment of the function. Valid values: nodejs6, nodejs8, nodejs10, nodejs12, python2.7, python3, java8, java11, php7.2, dotnetcore2.1, custom runtime, and custom container.
  • --timeout number: the timeout period for the execution of the function. Unit: seconds. Default value: 60.
  • --caPort number: the port on which the HTTP server listens for the custom runtime or custom container runtime.
Example:
  • macOS or Linux operating system
    s cli fc-api createFunction --serviceName mytest --functionName mytest --code '{"zipFile": "./"}' --handler index.handler --runtime python3
  • Windows operating system
    s cli fc-api createFunction --serviceName mytest --functionName mytest --code "{\"zipFile\": \"./\"}" --handler index.handler --runtime python3

For information about the API operation for creating a function, see CreateFunction.

Delete a function

Command syntax:
s cli fc-api deleteFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName>
Parameters:
  • --region string: the ID of the region where the resource is deployed.
  • --access string: the alias of the key used.
  • --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
  • --serviceName string: the name of the service.
  • --functionName string: the name of the function.
Example:
s cli fc-api deleteFunction --region cn-hangzhou --access default --serviceName mytest --functionName mytest

For information about the API operation for deleting a function, see DeleteFunction.

Modify a function

Command syntax:
s cli fc-api updateFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --description <description> --code <codefile> --customContainerConfig <customContainerConfig>  --handler <functionhandler> --runtime <runtime> --initializationTimeout <initializationTimeout> --initializer ----memorySize <momorysize> ----timeout <timeout> --caPort <caport>
Parameters:
  • --region string: the ID of the region where the resource is deployed.
  • --access string: the alias of the key used.
  • --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
  • --serviceName string: the name of the service.
  • --functionName string: the name of the function.
  • --code string: the ZIP code file.
  • --customContainerConfig string: the configuration of the custom container runtime. After you configure the custom container runtime, Function Compute can execute functions in a container created from a custom image.
  • --description string: the description of the function.
  • --handler string: the handler of the function. The handler is in the format of "file name.function name". For example, hello_world.handler indicates that the handler is the handler function in the hello_world.js file.
  • --initializationTimeout number: the timeout period for the execution of the initializer function.
  • --initializer string: the initializer function.
  • --memorySize number: the memory size for the function.
  • --runtime string: the runtime environment of the function. Valid values: nodejs6, nodejs8, nodejs10, nodejs12, python2.7, python3, java8, java11, php7.2, dotnetcore2.1, custom runtime, and custom container.
  • --timeout number: the timeout period for the execution of the function. Unit: seconds. Default value: 60.
  • --caPort number: the port on which the HTTP server listens for the custom runtime or custom container runtime.
Example:
  • macOS or Linux operating system
    s cli fc-api updateFunction --serviceName mytest --functionName mytest --code '{"zipFile": "./"}' --timeout 31
  • Windows operating system
    s cli fc-api updateFunction --serviceName mytest --functionName mytest --code "{\"zipFile\": \"./\"}" --timeout 31

For information about the API operation for modifying a function, see UpdateFunction.

Query the information about a function

Command syntax:
s cli fc-api getFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --qualifier <version or alias>
Parameters:
  • --region string: the ID of the region where the resource is deployed.
  • --access string: the alias of the key used.
  • --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
  • --serviceName string: the name of the service.
  • --functionName string: the name of the function.
  • --qualifier string: the alias or version of the service.
Example:
s cli fc-api getFunction --serviceName mytest --functionName mytest --qualifier LATEST

For information about the API operation for querying the information about a function, see GetFunction.

Query the code of a function

Command syntax:
s cli fc-api getFunctionCode --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --qualifier <version or alias>
Parameters:
  • --region string: the ID of the region where the resource is deployed.
  • --access string: the alias of the key used.
  • --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
  • --serviceName string: the name of the service.
  • --functionName string: the name of the function.
  • --qualifier string: the alias or version of the service.
Example:
s cli fc-api getFunctionCode --region cn-hangzhou --serviceName mytest --functionName mytest --qualifier LATEST

For information about the API operation for querying the code of a function, see GetFunctionCode.

Query functions

Command syntax:
s cli fc-api listFunctions --region <regionid> --access <accessname> --props <props> --serviceName mytest --qualifier <version or alias> --limit <limit number> --nextToken <nextresult> --prefix <return prefix> --startkey <startkey>
Parameters:
  • --region string: the ID of the region where the resource is deployed.
  • --access string: the alias of the key used.
  • --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
  • --limit string: the maximum number of resources to be returned.
  • --nextToken string: the token used to return more results. If the number of resources exceeds the limit, the nextToken parameter is returned. Include this parameter in subsequent calls to obtain more results. You do not need to provide this parameter in the first call.
  • --prefix string: the prefix that the names of returned resources must contain.
  • --startKey string: the start position of the result list. Results are in alphabetical order, and the results that follow startKey (inclusive) are listed.
  • --serviceName string: the name of the service.
  • --qualifier string: the alias or version of the service.
Example:
s cli fc-api listFunctions --serviceName mytest --qualifier LATEST

For information about the API operation for querying functions, see ListFunctions.

Invoke a function

Command syntax:
s cli fc-api invokeFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --event <event>
Parameters:
  • --region string: the ID of the region where the resource is deployed.
  • --access string: the alias of the key used.
  • --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
  • --serviceName string: the name of the service.
  • --functionName string: the name of the function.
  • --event string: the event that triggers the execution of the function.
Example:
s cli fc-api invokeFunction --region cn-hangzhou --serviceName mytest --functionName mytest

For information about the API operation for invoking a function, see InvokeFunction.