All Products
Search
Document Center

:Function-related commands

Last Updated:Apr 01, 2026

Use the FC component—an operation tool built on Serverless Devs—to manage functions in Function Compute by running CLI commands that call the Function Compute API directly.

Prerequisites

Before you begin, ensure that you have:

Commands overview

CommandOperation
CreateFunctionCreate a function
DeleteFunctionDelete a function
UpdateFunctionUpdate a function
GetFunctionGet function configurations
GetFunctionCodeGet function code
ListFunctionsList functions
InvokeFunctionInvoke a function

All commands share the following common parameters:

ParameterRequiredDescription
--regionYesThe region where resources are deployed
--access / -aNoThe alias of the key to use
--apiVersionNoThe API version. Valid values: 20210416 and 20160815

On macOS and Linux, prefix each command with sudo. On Windows, omit sudo.

Create a function

Creates a function in the specified service.

Syntax

sudo s cli fc api CreateFunction
  --region <regionid>
  [--access <accessname>]
  [--apiVersion <version>]
  --path '{"serviceName": "<serviceName>"}'
  --body '{
    "functionName": "<functionName>",
    "handler": "<handler>",
    ["code": <code>,]
    ["customContainerConfig": <customContainerConfig>,]
    ["layers": "<layerName>",]
    ["description": "<description>",]
    ["initializationTimeout": <seconds>,]
    ["initializer": "<initializer>",]
    ["memorySize": <MB>,]
    ["runtime": "<runtime>",]
    ["timeout": <seconds>,]
    ["caPort": <port>,]
    ["environmentVariables": <envVars>,]
    ["instanceConcurrency": <concurrency>,]
    ["instanceType": "<instanceType>",]
    ["instanceLifecycleConfig": <lifecycleConfig>,]
    ["customDNS": <dnsConfig>,]
    ["customRuntimeConfig": <runtimeConfig>]
  }'
  [--header '{"X-Fc-Code-Checksum": "<checksum>"}']

Parameters

*Path parameters*

ParameterRequiredTypeDescription
--serviceNameYesstringThe service name

*Body parameters*

ParameterRequiredTypeDescription
--functionNameYesstringThe function name
--handlerYesstringThe function handler in <filename>.<functionname> format. Example: hello_world.handler calls the handler function in hello_world.js
--codeNostringThe compressed code package in ZIP format
--customContainerConfigNostringThe Custom Container runtime configuration. After configuration, you can use custom container images to invoke functions
--layersNostringThe layer name
--descriptionNostringThe function description
--initializationTimeoutNonumberThe timeout period for function initialization
--initializerNostringThe Initializer function
--memorySizeNonumberThe memory size for function execution
--runtimeNostringThe runtime
--timeoutNonumberThe timeout period for function execution. Default: 60s
--caPortNonumberThe listening port of the HTTP server in a custom runtime or Custom Container runtime
environmentVariablesNoobjectThe environment variables
instanceConcurrencyNonumberThe concurrency of function instances
instanceTypeNostringThe function instance type
instanceLifecycleConfigNoobjectThe instance lifecycle hook configurations
customDNSNoobjectThe custom Domain Name System (DNS) configuration
customRuntimeConfigNoobjectThe custom runtime configuration

*Header parameters*

ParameterRequiredDescription
X-Fc-Code-ChecksumNoThe CRC-64 checksum of the function code package

Examples

macOS or Linux:

  • Programming language runtime:

    sudo s cli fc api CreateFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest"}'  --body '{"functionName": "mytest","code": {"ossBucketName": "testbucket","ossObjectName": "code.zip"},"handler": "index.handler","runtime": "python3"}'
  • Custom Container runtime:

    sudo s cli fc api CreateFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest"}' --body '{"functionName": "mytest","customContainerConfig": {"image": "registry.cn-hangzhou.aliyuncs.com/zh****/zh****:v0.1"},"handler": "index.handler","runtime": "custom-container"}'

Windows:

  • Programming language runtime:

    s cli fc api CreateFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest"}'  --body '{"functionName": "mytest","code": {\"ossBucketName\": \"testbucket\",\"ossObjectName\": \"code.zip\"},"handler": "index.handler","runtime": "python3"}'
  • Custom Container runtime:

    s cli fc api CreateFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest"}' --body '{"functionName": "mytest","customContainerConfig": {\"image\": \"registry.cn-hangzhou.aliyuncs.com/zh****/zh****:v0.1\"},"handler": "index.handler","runtime": "custom-container"}'

For the full API reference, see CreateFunction.

Delete a function

Deletes a function from the specified service.

Warning

Deletion is permanent and cannot be undone. Verify that you have specified the correct service name and function name before running this command.

Syntax

sudo s cli fc api DeleteFunction
  --region <regionid>
  [--access <accessname>]
  [--apiVersion <version>]
  --path '{"serviceName": "<serviceName>", "functionName": "<functionName>"}'
  [--header '{"If-Match": "<etag>"}']

Parameters

*Path parameters*

ParameterRequiredTypeDescription
--serviceNameYesstringThe service name
--functionNameYesstringThe function name

*Header parameters*

ParameterRequiredDescription
--If-MatchNoEnsures that the resource you are deleting is the same as the resource you intended to delete

Example

sudo s cli fc api DeleteFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest","functionName": "mytest"}'

For the full API reference, see DeleteFunction.

Update a function

Updates the configuration or code of an existing function.

Syntax

sudo s cli fc api UpdateFunction
  --region <regionid>
  [--access <accessname>]
  [--apiVersion <version>]
  --path '{"serviceName": "<serviceName>", "functionName": "<functionName>"}'
  --body '{
    ["code": <code>,]
    ["customContainerConfig": <customContainerConfig>,]
    ["layers": "<layerName>",]
    ["description": "<description>",]
    "handler": "<handler>",
    ["initializationTimeout": <seconds>,]
    ["initializer": "<initializer>",]
    ["memorySize": <MB>,]
    ["runtime": "<runtime>",]
    ["timeout": <seconds>,]
    ["caPort": <port>,]
    ["instanceConcurrency": <concurrency>,]
    ["instanceType": "<instanceType>",]
    ["instanceLifecycleConfig": <lifecycleConfig>,]
    ["customDNS": <dnsConfig>,]
    ["customRuntimeConfig": <runtimeConfig>]
  }'
  [--header '{"If-Match": "<etag>", "X-Fc-Code-Checksum": "<checksum>"}']

Parameters

*Path parameters*

ParameterRequiredTypeDescription
--serviceNameYesstringThe service name
--functionNameYesstringThe function name

*Body parameters*

ParameterRequiredTypeDescription
--handlerYesstringThe function handler in <filename>.<functionname> format. Example: hello_world.handler
--codeNostringThe compressed code package in ZIP format
--customContainerConfigNostringThe Custom Container runtime configuration
--layersNostringThe layer name
--descriptionNostringThe function description
--initializationTimeoutNonumberThe timeout period for function initialization
--initializerNostringThe Initializer function
--memorySizeNonumberThe memory size for function execution
--runtimeNostringThe runtime
--timeoutNonumberThe timeout period for function execution. Default: 60s
--caPortNonumberThe listening port of the HTTP server in a custom runtime or Custom Container runtime
instanceConcurrencyNonumberThe concurrency of function instances
instanceTypeNostringThe function instance type
instanceLifecycleConfigNoobjectThe instance lifecycle hook configurations
customDNSNoobjectThe custom DNS configuration
customRuntimeConfigNoobjectThe custom runtime configuration

*Header parameters*

ParameterRequiredDescription
--If-MatchNoEnsures that the resource you are updating is the same as the resource you intended to update
X-Fc-Code-ChecksumNoThe CRC-64 checksum of the function code package

Examples

macOS or Linux:

  • Programming language runtime:

    sudo s cli fc api UpdateFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest","functionName": "mytest"}' --body '{"code": {"ossBucketName": "testbucket","ossObjectName": "code.zip"},"timeout": 31}'
  • Custom Container runtime:

    sudo s cli fc api UpdateFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest","functionName": "mytest"}' --body '{"customContainerConfig": {"image": "registry.cn-hangzhou.aliyuncs.com/zh****/zh****:v0.1"},"runtime": "custom-container","timeout": 31}'

Windows:

  • Programming language runtime:

    s cli fc api UpdateFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest","functionName": "mytest"}' --body '{"code": {\"ossBucketName\": \"testbucket\",\"ossObjectName\": \"code.zip\"},"timeout": 31}'
  • Custom Container runtime:

    s cli fc api UpdateFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest","functionName": "mytest"}' --body '{"customContainerConfig": {\"image\": \"registry.cn-hangzhou.aliyuncs.com/zh****/zh****:v0.1\"},"runtime": "custom-container","timeout": 31}'

For the full API reference, see UpdateFunction.

Get function configurations

Retrieves the configuration details of a function, optionally scoped to a specific version or alias.

Syntax

sudo s cli fc api GetFunction
  --region <regionid>
  [--access <accessname>]
  [--apiVersion <version>]
  --path '{"serviceName": "<serviceName>", "functionName": "<functionName>", ["qualifier": "<versionOrAlias>"]}'

Parameters

*Path parameters*

ParameterRequiredTypeDescription
--serviceNameYesstringThe service name
--functionNameYesstringThe function name
--qualifierNostringThe service version or alias

Example

sudo s cli fc api GetFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest","functionName": "mytest","qualifier": "LATEST"}'

For the full API reference, see GetFunction.

Get function code

Queries the code of a function, optionally scoped to a specific version or alias.

Syntax

sudo s cli fc api GetFunctionCode
  --region <regionid>
  [--access <accessname>]
  [--apiVersion <version>]
  --path '{"serviceName": "<serviceName>", "functionName": "<functionName>", ["qualifier": "<versionOrAlias>"]}'

Parameters

*Path parameters*

ParameterRequiredTypeDescription
--serviceNameYesstringThe service name
--functionNameYesstringThe function name
--qualifierNostringThe service version or alias

Example

sudo s cli fc api GetFunctionCode --region cn-hangzhou --access default --path '{"serviceName": "mytest","functionName": "mytest","qualifier": "LATEST"}'

For the full API reference, see GetFunctionCode.

List functions

Lists all functions in a service. Use pagination parameters to retrieve large result sets.

Syntax

sudo s cli fc api ListFunctions
  --region <regionid>
  [--access <accessname>]
  [--apiVersion <version>]
  --path '{"serviceName": "<serviceName>", ["qualifier": "<versionOrAlias>"]}'
  [--query '{"limit": "<limit>", "nextToken": "<token>", "prefix": "<prefix>", "startKey": "<startKey>"}']

Parameters

*Path parameters*

ParameterRequiredTypeDescription
--serviceNameYesstringThe service name
--qualifierNostringThe service version or alias

*Query parameters*

ParameterRequiredTypeDescription
--limitNostringThe maximum number of functions to return
--nextTokenNostringThe pagination token from a previous response. Include this in subsequent requests to retrieve the next page of results. Omit on the first request
--prefixNostringFilters results to functions whose names start with this prefix
--startKeyNostringReturns results alphabetically starting from the first name after this key (inclusive)

Example

sudo s cli fc api ListFunctions --region cn-hangzhou --access default --path '{"serviceName": "mytest","qualifier": "LATEST"}'

For the full API reference, see ListFunctions.

Invoke a function

Invokes a function synchronously or asynchronously.

Syntax

sudo s cli fc api InvokeFunction
  --region <regionid>
  [--access <accessname>]
  [--apiVersion <version>]
  --path '{"serviceName": "<serviceName>", "functionName": "<functionName>", ["qualifier": "<versionOrAlias>"]}'
  [--body "<payload>"]
  [--header '{
    ["X-Fc-Invocation-Type": "Sync | Async",]
    ["X-Fc-Log-Type": "Tail | None",]
    ["X-Fc-Stateful-Async-Invocation-Id": "<invocationId>"]
  }']

Parameters

*Path parameters*

ParameterRequiredTypeDescription
--serviceNameYesstringThe service name
--functionNameYesstringThe function name
--qualifierNostringThe service version or alias

*Body*

ParameterRequiredDescription
--bodyNoThe payload data passed to the function

*Header parameters*

ParameterRequiredDescription
X-Fc-Invocation-TypeNoThe invocation method. Valid values: Sync (synchronous) and Async (asynchronous)
X-Fc-Log-TypeNoThe log return method. Valid values: Tail (returns the last 4 KB of logs) and None (no logs returned). Default: None
X-Fc-Stateful-Async-Invocation-IdNoThe ID of the stateful asynchronous invocation. If not specified, the system generates one automatically

Example

sudo s cli fc api InvokeFunction --region cn-hangzhou --access default --path '{"serviceName": "mytest","functionName": "mytest","qualifier": "LATEST"}'  --body "hello fc payload" --header '{"X-Fc-Invocation-Type": "Async","X-Fc-Log-Type": "None"}'

For the full API reference, see InvokeFunction.