In the non-YAML mode of the FC component, you can use the CLI to manage resources without the need to create and configure the s.yaml file. For example, if you want to synchronize managed resources, but you do not want to reconfigure parameters after you deploy resources online, you need only to run the s cli fc sync command to synchronize resources from the cloud to your local computer. This topic describes how to use the FC component in CLI mode to manage resources.

Prerequisites

Supported commands

When you use Serverless Devs to manage Function Compute, new resources may be generated. If you set VPC to Auto when you deploy a resource, you cannot check the resource status when the resource is online. To resolve this issue, the FC component allows you to run the s cli fc info command to query the status of an online resource.

Command syntax:

s cli fc info --region <regionid> --service-name <serviceName> --function-name <functionName> --trigger-name <triggerName>

Parameters:

  • --function-name string: the name of the function.
  • --region string: the ID of the region.
  • --service-name string: the name of the service.
  • --trigger-name string: the name of the trigger.

Example:

s cli fc info --region cn-hangzhou --service-name serviceName 

The FC component allows you to run the s cli fc invoke command to invoke a function online.

Command syntax:

s cli fc invoke --event <payload>  --event-file <file-path> --region <regionid> --service-name <serviceName> --function-name <functionName>  --event-stdin --invocation-type <async>

Parameters:

  • --event string: the event data that you want to pass into a function when you invoke the function.
  • --event-file string: the file that you want to use. If the function that you want to invoke is an event function, you must specify the file that contains event data. If the function that you want to invoke is an HTTP function, you must specify the file that contains HTTP request settings.
  • --event-stdin string: specifies whether to read data from the standard input or a pipeline.
  • --function-name string: the name of the function.
  • --invocation-type string: the type of the invocation. Valid values: sync and async. Default value: sync.
  • --region string: the ID of the region.
  • --service-name string: the name of the service.

Example:

s cli fc invoke --region cn-hangzhou --function-name test --invocation-type async 

When you use the FC component to deploy resources, you may need to check the online logs. The FC component allows you to run the s cli fc logs command to query the logs.

Command syntax:

s cli fc logs -s <starttime> -e <endtime> --region <regionid> --request-id <requestID> --service-name <serviceName> --function-name <functionName> --keyword <test> --tail boolean --type <failed>

Parameters:

  • -e or --end-time string: the end of the time range to query.
  • --function-name string: the name of the function.
  • --keyword string: the keyword.
  • --region string: the ID of the region.
  • --request-id string: the ID of the request.
  • --service-name string: the name of the service.
  • -s or --start-time string: the beginning of the time range to query.
  • --tail boolean: specifies whether to continuously return logs.
  • --type string: the type of logs that you want to query.

Example:

s cli fc logs --region cn-hangzhou --service-name serviceName --function-name functionName

You can query specific metrics of a deployed function, such as the number of invocations, number of successful executions, and number of failed executions. The FC component allows you to run the s cli fc metrics command to query the metrics of a function.

Command syntax:

s cli fc metrics --region <regionid> --service-name <serviceName> --function-name <functionName>

Parameters:

  • --function-name string: the name of the function.
  • --region string: the ID of the region.
  • --service-name string: the name of the service.

Example:

s cli fc metrics --region cn-hangzhou --service-name serviceName --function-name functionName

After you run the preceding command, a URL is returned in the command output. Visit the URL in a browser to view the metrics of the specified resource.

After you deploy resources to Function Compute, you can use the FC component to manage new resources and existing resources in Function Compute. This way, you do not need to configure resources. The FC component allows you to run the s cli fc sync command to synchronize the configurations of resources.

Command syntax:

s cli fc sync -f --region <regionid> --service-name <serviceName> --function-name <functionName> --target-dir <storage directory> --trigger-name <triggername> --type <all>

Parameters:

  • -f or --force boolean: specifies whether to forcibly overwrite the code file.
  • --function-name string: the name of the function.
  • --region string: the ID of the region.
  • --service-name string: the name of the service.
  • --target-dir string: the storage directory. If no directory is specified, the current directory is used.
  • --trigger-name string: the name of the trigger.
  • --type string: the operation that you want to perform. Valid values: code, config, and all.

Example:

s cli fc sync --region cn-hangzhou --service-name serviceName --function-name functionName --type config

The FC component allows you to run the s cli fc version command to manage the version of a service. The s cli fc version command contains the following subcommands: s cli fc version publish and s cli fc version list.

  • s cli fc version publish: publishes a version.

    Command syntax:

    s cli fc version publish --region <regionid> --service-name <serviceName> --description <description>

    Parameters:

    • --description string: the description of the version.
    • --region string: the ID of the region.
    • --service-name string: the name of the service.

    Example:

    s cli fc version publish --region cn-hangzhou --service-name serviceName

  • s cli fc version list: queries a list of versions.

    Command syntax:

    s cli fc version list --region <regionid> --service-name <serviceName> --table boolean

    Parameters:

    • --region string: the ID of the region.
    • --service-name string: the name of the service.
    • --table boolean: specifies whether to return versions in a table.

    Example:

    s cli fc version list --region cn-hangzhou --service-name serviceName --table boolean

The FC component allows you to run the s fc cli alias command to configure an alias for a service. The s cli fc alias command contains the following subcommands: s cli fc alias publish, s cli fc alias get, and s cli fc alias list.

  • s cli fc alias publish: publishes an alias.

    Command syntax:

    s cli fc alias publish --alias-name <aliasName> --description <description> --gversion <grayscale version id> --region <regionid> --service-name <serviceName> --function-name <functionName> --version-id <versionID> --weight <weight parameter >

    Parameters:

    • --alias-name string: the name of the alias.
    • --description string: the description of the alias.
    • --gversion string: the ID of the canary release version.
    • --region string: the ID of the region.
    • --service-name string: the name of the service.
    • --version-id string: the version to which the alias points.
    • --weight string: the weight of the canary release version.

    Example:

    s cli fc alias publish --version-id 3  --alias-name aliasName

  • s cli fc alias get: queries the details of an alias.

    Command syntax:

    s cli fc alias get --alias-name <aliasName> --region <regionid> --service-name <serviceName> 

    Parameters:

    • --alias-name string: the name of the alias.
    • --region string: the ID of the region.
    • --service-name string: the name of the service.

    Example:

    s cli fc alias get --region cn-hangzhou --alias-name aliasName

  • s cli fc alias list: queries a list of aliases.

    Command syntax:

    s cli fc alias list --table boolean --region <regionid> --service-name <serviceName> 

    Parameters:

    • --region string: the ID of the region.
    • --service-name string: the name of the service.
    • --table boolean: specifies whether to return aliases in a table.

    Example:

    s cli fc alias list --region cn-hangzhou --service-name serviceName

The FC component allows you to run the s cli fc provision command to manage provisioned resources. The s cli fc provision command contains the following subcommands: s cli fc provision list, s cli fc provision put, and s cli fc provision get.

  • s cli fc provision put: configures provisioned resources.

    Command syntax:

    s cli fc provision put --config <configuration path> --qualifier <qualifier> --region <regionid> --target <target parameter> --service-name <serviceName> 

    Parameters:

    • --config string: the configuration path.
    • --qualifier string: the version or alias of the service.
    • --region string: the ID of the region.
    • --service-name string: the name of the service.
    • --target number: the number of provisioned resources.

    Example:

    s cli fc provision put --target 1 --qualifier alias

  • s cli fc provision list: queries a list of provisioned resources.

    Command syntax:

    s cli fc provision list --table boolean --qualifier <qualifier> --region <regionid> --service-name <serviceName> 

    Parameters:

    • --region string: the ID of the region.
    • --service-name string: the name of the service.
    • --qualifier string: the version or alias of the service.
    • --table boolean: specifies whether to return aliases in a table.

    Example:

    s cli fc provision list --region cn-hangzhou --service-name serviceName

  • s cli fc provision get: queries the details of a provisioned instance.

    Command syntax:

    s cli fc provision get --qualifier <qualifier> --region <regionid> --function-name <functionName> --service-name <serviceName> 

    Parameters:

    • --function-name string: the name of the function.
    • --qualifier string: the version or alias of the service.
    • --region string: the ID of the region.
    • --service-name string: the name of the service.

    Example:

    s cli fc provision get --qualifier test

The FC component allows you to run the s cli fc onDemand command to manage on-demand instances. The s cli fc onDemand command contains the following subcommands: s cli fc onDemand put, s cli fc onDemand list, and s cli fc onDemand get.

  • s cli fc onDemand put: configures on-demand instances.

    Command syntax:

    s cli fc onDemand put --function-name <functionName> --max  <maximumInstanceCount > --qualifier <qualifier> --region <regionid> --service-name <serviceName> 

    Parameters:

    • --function-name string: the name of the function.
    • --max or --maximum-instance-count string: the maximum number of on-demand instances.
    • --qualifier string: the version or alias of the service.
    • --region string: the ID of the region.
    • --service-name string: the name of the service.

    Example:

    s cli fc onDemand put --qualifier test --max 1 

  • s cli fc onDemand list: queries a list of on-demand instances.

    Command syntax:

    s cli fc onDemand list --table boolean --region <regionid> --service-name <serviceName> 

    Parameters:

    • --region string: the ID of the region.
    • --service-name string: the name of the service.
    • --table boolean: specifies whether to return on-demand instances in a table.

    Example:

    s cli fc onDemand list --table boolean

  • s cli fc onDemand get: queries the details of an on-demand instance.

    Command syntax:

    s cli fc onDemand get --function-name <functionName> --qualifier <qualifier> --region <regionid> --service-name <serviceName> 

    Parameters:

    • --function-name string: the name of the function.
    • --qualifier string: the version or alias of the service.
    • --region string: the ID of the region.
    • --service-name string: the name of the service.

    Example:

    s cli fc onDemand get --qualifier test

Layers allow you to publish and deploy custom resources such as public libraries, runtime environments, and function extensions. You can use a layer to abstract the public libraries on which a function depends. This reduces the sizes of code packages when you deploy or update the function. You can also deploy a custom runtime as a layer to share the runtime among multiple functions.

The FC component allows you to run the s cli fc layer command to configure a layer. The s cli fc layer command contains the following subcommands: s cli fc layer publish, s cli fc layer list, s cli fc layer versionConfig, and s cli fc layer versions.

  • s cli fc layer publish: publishes a layer version.

    Command syntax:

    s cli fc layer publish --code <codefile> --compatible-runtime <Runtime> --description <description> --region <regionid> --layer-name <layerName>

    Parameters:

    • --code string: the code file in the ZIP format.
    • --compatible-runtime string: the runtime environment of the layer.
    • --description string: the description of the layer.
    • --layer-name string: the name of the layer.
    • --region string: the ID of the region.

    Example:

    s cli fc layer publish --layer-name testName --code ./
  • s cli fc layer list: queries a list of layers.

    Command syntax:

    s cli fc layer list --prefix <prefix> --region <regionid> --table boolean

    Parameters:

    • --prefix string: the name prefix of the layers that you want to query.
    • --region string: the ID of the region.
    • --table boolean: specifies whether to return on-demand instances in a table.

    Example:

    s cli fc layer list --table boolean
  • s cli fc layer versionConfig: queries the details of a layer version.

    Command syntax:

    s cli fc layer versionConfig --layer-name <layerName> --region <regionid> --version-id <version>

    Parameters:

    • --layer-name string: the name of the layer.
    • --region string: the ID of the region.
    • --version-id number: the layer version that you want to query.

    Example:

    s cli fc layer versionConfig --layer-name layerName --version-id 2
  • s cli fc layer versions: queries the versions of a layer.

    Command syntax:

    s cli fc layer versions --layer-name <layerName> --region <regionid> --table boolean

    Parameters:

    • --layer-name string: the name of the layer.
    • --region string: the ID of the region.
    • --table boolean: specifies whether to return the version of the specified layer in a table.

    Example:

    s cli fc layer versions --layer-name layerName --table boolean

The FC component allows you to run the s cli fc stress command to perform stress testing on a function. The s cli fc stress command contains the following subcommands: s cli fc stress start and s cli fc stress clean.

  • s cli fc stress start: starts stress testing.

    Command syntax:

    Event functions:

    s cli fc stress start --function-name <functionName> --num-user <6> --payload <"hello world"> --payload-file <./payload.file> --function-type <event> --region <regionid> --service-name <serviceName> --qualifier <LATEST> --run-time <30> --spawn-rate <2>

    HTTP functions:

    s cli fc stress start --function-name <functionName> --method <POST> --num-user <6> --payload <"hello world"> --payload-file <./payload.file> --function-type <http> --region <regionid> --service-name <serviceName> --run-time <30> --spawn-rate <2> --url <myUrl>

    Parameters:

    • --function-name string: the name of the function.
    • --function-type string: the type of the function. Valid values: http andevent.
    • --method string: the request method of the function. Valid values: GET, POST, PUT, PATCH, DELETE, OPTIONS, and HEAD. If you set--function-type to http, you must specify this parameter.
    • --num-user number: the number of users that participate in stress testing.
    • --payload string: the input of the function. Valid values:
      • The event that is passed into the function if you set --function-type string to event.
      • The request body that is passed into the function if you set --function-type string to http.
    • --payload-file string: the file path, which varies based on the function type. Valid values:
      • The file path of the event that is passed into the function if you set --function-type string to event.
      • The file path of the request body that is passed into the function if you set --function-type string to http.
    • -q or --qualifier string: the version or alias of the function. If you set --function-type to event, you must specify this parameter.
    • --region string: the region where the function resides.
    • --run-time number: the time required for stress testing on the function.
    • --service-name string: the name of the service.
    • --spawn-rate number: the number of users increased per second.
    • -u or --url string: the specified URL. If you set --function-type to http, you must specify this parameter.

    Example:

    • Event functions:

      s cli fc stress start --num-user 6 --spawn-rate 10 --run-time 30 --function-type event --service-name serviceName --function-name functionName --qualifier LATEST --payload "hello world" --region cn-shanghai --access   default

    • HTTP functions:

      s cli fc stress start --num-user 6 --spawn-rate 10 --run-time 30 --function-type http --url https://188077086902****.cn-shanghai.fc.aliyuncs.com/2016-08-15/proxy/demo.LATEST/test/  --method POST --payload "hello world" --region cn-shanghai --access default 

  • (Optional) s cli fc stress clean: clears the stress testing environment.

    Command syntax:

    s cli fc stress clean --region <regionid> -y 

    Parameters:

    • -y or --assume-yes: sets the answers to all questions to yes in the command output.
    • --region string: the ID of the region.

    Example:

    s cli fc stress clean --region cn-hangzhou -y

The FC component allows you to run the s cli fc eval command to quickly detect memory or detect concurrency of an event function or HTTP function.

s cli fc eval start: starts detection.

Command syntax:

s cli fc eval start --region <regionid> --function-name  <functionName> --service-name <serviceName> --function-type <functiontype> --eval-type <evaltype> --run-count <Number>  --payload <'{"key":"val"}'> --memory-size <MemorySize List>  --access <accessName>

Parameters:

  • --eval-type string: the type of detection. Valid values: memory and concurrency.
  • --concurrency-args string: the concurrency range and the step size of the function. Example: --concurrency-args 2,20,5. In this example, the value indicates that the concurrency range is 2 to 20 and the step size is 5. The function is detected in concurrency values of 2, 7, 12, and 17. If you set --eval-type string to concurrency, you must specify this parameter.
  • --function-name string: the name of the function.
  • --function-type string: the type of the function. Valid values: http and event.
  • --memory number: the memory size of the function. If you set --eval-type to concurrency, you must specify this parameter.
  • --memory-size string: the list of memory sizes of the function. The function at different memory settings is invoked. If you set --eval-type to memory, you must specify this parameter.
  • --method string: the request method of the function. Valid values: GET, POST, PUT, PATCH, DELETE, OPTIONS, and HEAD. If you set --function-type to http, you must specify this parameter.
  • --path string: the specified path. If you set --function-type to http, you must specify this parameter.
  • --payload string: the input of the function. Valid values:
    • The event that is passed into the function if you set --function-type string to event.
    • The request body that is passed into the function if you set --function-type string to http.
  • -f or --payload-file string: the file path, which varies based on the function type. Valid values:
    • The file path of the event that is passed into the function if you set --function-type string to event.
    • The file path of the request body that is passed into the function if you set --function-type string to http.
  • -r or --region string: the ID of the region.
  • --query string: the specified query. If you set --function-type to http, you must specify this parameter.
  • --rt number: the maximum response time. If you set --eval-type to concurrency, you must specify this parameter.
  • --run-count number: the frequency that the desired function is invoked when different memory sizes are allocated. If you set --eval-type to memory, you must specify this parameter.
  • --service-name string: the name of the service.

Example:

Memory detection:

s cli fc eval start --region cn-hangzhou --function-name cpu-test --service-name dsp-test --function-type event  --eval-type memory  --run-count 10 --payload '{"key":"val"}' --memory-size 128,256,512,1024  --access default

Concurrency detection:

s cli fc eval start --region cn-hangzhou --function-name demo --service-name Service --function-type http --eval-type concurrency --memory 1536 --concurrency-args 2,20,5 --rt 200 --method=get --path /login  --query 'a=1&b=2' --access default