If you do not want to use a YAML file to manage resources, you can use the command mode instead. This topic describes how to use the command mode of the FC component to manage resources.

Prerequisites

Supported commands

When you use Serverless Devs to manage Function Compute, specific new resources may be generated in Function Compute. For example, if you set the Virtual Private Cloud (VPC) setting to Auto when you deploy an on-premises resource to Function Compute, the resource can be properly deployed. However, you cannot check the status of the resource after it is brought online. To resolve this issue, FC provides the s cli fc info command for you 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 that you want to query.
  • --region string: the region where the resource that you want to query resides.
  • --service-name string: the name of the service that you want to query.
  • --trigger-name string: the name of the trigger that you want to query.

Example:

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

FC 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 to be passed to the function during the invocation.
  • --event-file string: the path of the file to be used. If the function to be invoked is an event function, the file is the one that contains the event data. If the function to be invoked is an HTTP function, the file is the one that contains the HTTP request settings.
  • --event-stdin string: specifies whether to read data from the standard input (stdin) or a script pipeline.
  • --function-name string: the name of the function to be invoked.
  • --invocation-type string: the type of the invocation. Valid values: sync and async. Default value: sync.
  • --region string: the region where the function resides.
  • --service-name string: the name of the service that contains the function.

Example:

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

When you use FC to perform operations such as resource deployment, you may need to check the online logs. FC allows you to run the s cli fc logs command to query the logs of a resource.

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 whose logs you want to query.
  • --keyword string: the keyword used to filter logs.
  • --region string: the region where the function resides.
  • --request-id string: the ID of the request the log for which you want to query.
  • --service-name string: the name of the service that contains the function.
  • -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 may want to query specific metrics of a deployed function, such as the number of invocations, number of successful executions, and number of failed executions. FC 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 whose metrics you want to query.
  • --region string: the region where the function resides.
  • --service-name string: the name of the service that contains the function.

Example:

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

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

After you deploy a resource to Function Compute, you can use FC to manage both the new resource and existing resources in Function Compute. This frees you from manually configuring resources. FC allows you to run the s cli fc sync command to synchronize the code or configuration of a resource to Function Compute.

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 forcible overwrite the code file.
  • --function-name string: the name of the function whose code or configuration you want to synchronize.
  • --region string: the region where the function resides.
  • --service-name string: the name of the service that contains the function.
  • --target-dir string: the file storage path. The current path is used if no other path is specified.
  • --trigger-name string: the name of the trigger whose code or configuration you want to synchronize.
  • --type string: the operation to be performed. Valid values: code, config, and all.

Example:

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

FC allows you to run the s cli fc version command to manage service versions. s cli fc version contains two subcommands: s cli fc version publish and s cli fc version list.

  • s cli fc version publish: Publish a version.

    Command syntax:

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

    Parameters:

    • --description string: the description of the version to be published.
    • --region string: the region where the service resides.
    • --service-name string: the name of the service for which you want to publish the version.

    Example:

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

  • s cli fc version list: Query versions.

    Command syntax:

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

    Parameters:

    • --region string: the region where the service resides.
    • --service-name string: the name of the service whose versions you want to query.
    • --table boolean: specifies whether to return versions in the form of a table.

    Example:

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

FC allows you to run the s fc cli alias command to manage service aliases. s cli fc alias contains three subcommands: s cli fc alias publish, s cli fc alias get, and s cli fc alias list.

  • s cli fc alias publish: Set an alias for a service.

    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 alias to be set.
    • --description string: the description of the alias.
    • --gversion string: the ID of the canary release version.
    • --region string: the region where the service resides.
    • --service-name string: the name of the service for which you want to set an alias.
    • --version-id string: the ID of 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: Query 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 alias whose details you want to query.
    • --region string: the region where the service resides.
    • --service-name string: the name of the service to which the alias belongs.

    Example:

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

  • s cli fc alias list: Query aliases.

    Command syntax:

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

    Parameters:

    • --region string: the region where the service resides.
    • --service-name string: the name of the service whose aliases you want to query.
    • --table boolean: specifies whether to return aliases in the form of a table.

    Example:

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

FC allows you to run the s cli fc provision command to manage provisioned instances. s cli fc provision contains three subcommands: s cli fc provision list, s cli fc provision put, and s cli fc provision get.

  • s cli fc provision put: Configure provisioned instances.

    Command syntax:

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

    Parameters:

    • --config string: the path where the configuration is stored.
    • --qualifier string: the version or alias of the service for which you want to configure provisioned instances.
    • --region string: the region where the service resides.
    • --service-name string: the name of the service.
    • --target number: the number of provisioned instances to be configured for the service.

    Example:

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

  • s cli fc provision list: Query the provisioned instances for a service.

    Command syntax:

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

    Parameters:

    • --region string: the region where the service resides.
    • --service-name string: the name of the service whose provisioned instances you want to query.
    • --qualifier string: the version or alias of the service.
    • --table boolean: specifies whether to return provisioned instances in the form of a table.

    Example:

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

  • s cli fc provision get: Query the provisioned instances for a function.

    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 that you want to use the provisioned instances to execute.
    • --qualifier string: the version or alias of the service that contains the function.
    • --region string: the region where the service resides.
    • --service-name string: the name of the service.

    Example:

    s cli fc provision get --qualifier test

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

  • s cli fc onDemand put: Configure 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 that you want to use the on-demand instances to execute.
    • --max or --maximum-instance-count string: the maximum number of on-demand instances that can be used to execute the function.
    • --qualifier string: the version or alias of the service that contains the function.
    • --region string: the region where the service resides.
    • --service-name string: the name of the service.

    Example:

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

  • s cli fc onDemand list: Query the on-demand instances for a service.

    Command syntax:

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

    Parameters:

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

    Example:

    s cli fc onDemand list --table boolean

  • s cli fc onDemand get: Query the on-demand instances for a function.

    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 that you want to use the on-demand instances to execute.
    • --qualifier string: the version or alias of the service that contains the function.
    • --region string: the region where the service resides.
    • --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, runtimes, and function extensions. The public libraries on which a function depends can be abstracted to a layer. This reduces the size 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.

FC allows you to run the s cli fc layer command to manage layers. s cli fc layer contains four 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: Publish 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 ZIP file used to configure the layer.
    • --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 region where the layer resides.

    Example:

    s cli fc layer publish --layer-name testName --code ./
  • s cli fc layer list: Query layers.

    Command syntax:

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

    Parameters:

    • --prefix string: the name prefix of the layers you want to query.
    • --region string: the region where the layers you want to query reside.
    • --table boolean: specifies whether to return layers in the form of a table.

    Example:

    s cli fc layer list --table boolean
  • s cli fc layer versionConfig: Query 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 region where the layer resides.
    • --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: Query 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 region where the layer resides.
    • --table boolean: specifies whether to return layer versions in the form of a table.

    Example:

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