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

Prerequisites

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>
Parameter description:
  • --region string: 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.
Sample code:
  • macOS and Linux:
    • For a programming language runtime environment, run the following command to create a function:
      s cli fc-api createFunction --serviceName mytest --functionName mytest --code '{"zipFile": "./"}' --handler index.handler --runtime python3
    • For a custom container runtime environment, run the following command to create a function:
      s cli fc-api createFunction --serviceName mytest --functionName mytest --customContainerConfig '{"image": "registry-vpc.cn-shenzhen.aliyuncs.com/fc-demo/flask:v0.1"}' --handler index.handler --runtime custom-container
  • Windows:
    • For a programming language runtime environment, run the following command to create a function:
      s cli fc-api createFunction --serviceName mytest --functionName mytest --code "{\"zipFile\": \"./\"}" --handler index.handler --runtime python3
    • For a custom container runtime environment, run the following command to create a function:
      s cli fc-api createFunction --serviceName mytest --functionName mytest --customContainerConfig "{\"image\": \"registry-vpc.cn-shenzhen.aliyuncs.com/fc-demo/flask:v0.1\"}" --handler index.handler --runtime custom-container

For information about the API operation to create a function, see CreateFunction.

Delete a function

Command syntax:
s cli fc-api deleteFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName>
Parameter description:
  • --region string: 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.
Sample code:
s cli fc-api deleteFunction --region cn-hangzhou --access default --serviceName mytest --functionName mytest

For information about the API operation to delete a function, see DeleteFunction.

Update 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>
Parameter description:
  • --region string: 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.
Sample code:
  • macOS and Linux:
    • For a programming language runtime environment, run the following command to update a function:
      s cli fc-api updateFunction --serviceName mytest --functionName mytest --code '{"zipFile": "./"}' --timeout 31
    • For a custom container runtime environment, run the following command to update a function:
      s cli fc-api updateFunction --serviceName mytest --functionName mytest --code '{"zipFile": "./"}' --timeout 31 --customContainerConfig '{"image": "registry-vpc.cn-shenzhen.aliyuncs.com/fc-demo/flask:v0.1"}'
  • Windows:
    • For a programming language runtime environment, run the following command to update a function:
      s cli fc-api updateFunction --serviceName mytest --functionName mytest --code "{\"zipFile\": \"./\"}" --timeout 31
    • For a custom container runtime environment, run the following command to update a function:
      s cli fc-api updateFunction --serviceName mytest --functionName mytest --code "{\"zipFile\": \"./\"}" --timeout 31 --customContainerConfig "{\"image\": \"registry-vpc.cn-shenzhen.aliyuncs.com/fc-demo/flask:v0.1\"}"

For information about the API operation to update 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>
Parameter description:
  • --region string: 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.
Sample code:
s cli fc-api getFunction --serviceName mytest --functionName mytest --qualifier LATEST

For information about the API operation to query 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>
Parameter description:
  • --region string: 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.
Sample code:
s cli fc-api getFunctionCode --region cn-hangzhou --serviceName mytest --functionName mytest --qualifier LATEST

For information about the API operation to query the code of a function, see GetFunctionCode.

Query a list of 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>
Parameter description:
  • --region string: 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. 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.
Sample code:
s cli fc-api listFunctions --serviceName mytest --qualifier LATEST

For information about the API operation to query a list of 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>
Parameter description:
  • --region string: 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.
Sample code:
s cli fc-api invokeFunction --region cn-hangzhou --serviceName mytest --functionName mytest

For information about the API operation to invoke a function, see InvokeFunction.