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
| Command | Operation |
|---|---|
CreateFunction | Create a function |
DeleteFunction | Delete a function |
UpdateFunction | Update a function |
GetFunction | Get function configurations |
GetFunctionCode | Get function code |
ListFunctions | List functions |
InvokeFunction | Invoke a function |
All commands share the following common parameters:
| Parameter | Required | Description |
|---|---|---|
--region | Yes | The region where resources are deployed |
--access / -a | No | The alias of the key to use |
--apiVersion | No | The 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*
| Parameter | Required | Type | Description |
|---|---|---|---|
--serviceName | Yes | string | The service name |
*Body parameters*
| Parameter | Required | Type | Description |
|---|---|---|---|
--functionName | Yes | string | The function name |
--handler | Yes | string | The function handler in <filename>.<functionname> format. Example: hello_world.handler calls the handler function in hello_world.js |
--code | No | string | The compressed code package in ZIP format |
--customContainerConfig | No | string | The Custom Container runtime configuration. After configuration, you can use custom container images to invoke functions |
--layers | No | string | The layer name |
--description | No | string | The function description |
--initializationTimeout | No | number | The timeout period for function initialization |
--initializer | No | string | The Initializer function |
--memorySize | No | number | The memory size for function execution |
--runtime | No | string | The runtime |
--timeout | No | number | The timeout period for function execution. Default: 60s |
--caPort | No | number | The listening port of the HTTP server in a custom runtime or Custom Container runtime |
environmentVariables | No | object | The environment variables |
instanceConcurrency | No | number | The concurrency of function instances |
instanceType | No | string | The function instance type |
instanceLifecycleConfig | No | object | The instance lifecycle hook configurations |
customDNS | No | object | The custom Domain Name System (DNS) configuration |
customRuntimeConfig | No | object | The custom runtime configuration |
*Header parameters*
| Parameter | Required | Description |
|---|---|---|
X-Fc-Code-Checksum | No | The 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.
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*
| Parameter | Required | Type | Description |
|---|---|---|---|
--serviceName | Yes | string | The service name |
--functionName | Yes | string | The function name |
*Header parameters*
| Parameter | Required | Description |
|---|---|---|
--If-Match | No | Ensures 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*
| Parameter | Required | Type | Description |
|---|---|---|---|
--serviceName | Yes | string | The service name |
--functionName | Yes | string | The function name |
*Body parameters*
| Parameter | Required | Type | Description |
|---|---|---|---|
--handler | Yes | string | The function handler in <filename>.<functionname> format. Example: hello_world.handler |
--code | No | string | The compressed code package in ZIP format |
--customContainerConfig | No | string | The Custom Container runtime configuration |
--layers | No | string | The layer name |
--description | No | string | The function description |
--initializationTimeout | No | number | The timeout period for function initialization |
--initializer | No | string | The Initializer function |
--memorySize | No | number | The memory size for function execution |
--runtime | No | string | The runtime |
--timeout | No | number | The timeout period for function execution. Default: 60s |
--caPort | No | number | The listening port of the HTTP server in a custom runtime or Custom Container runtime |
instanceConcurrency | No | number | The concurrency of function instances |
instanceType | No | string | The function instance type |
instanceLifecycleConfig | No | object | The instance lifecycle hook configurations |
customDNS | No | object | The custom DNS configuration |
customRuntimeConfig | No | object | The custom runtime configuration |
*Header parameters*
| Parameter | Required | Description |
|---|---|---|
--If-Match | No | Ensures that the resource you are updating is the same as the resource you intended to update |
X-Fc-Code-Checksum | No | The 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*
| Parameter | Required | Type | Description |
|---|---|---|---|
--serviceName | Yes | string | The service name |
--functionName | Yes | string | The function name |
--qualifier | No | string | The 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*
| Parameter | Required | Type | Description |
|---|---|---|---|
--serviceName | Yes | string | The service name |
--functionName | Yes | string | The function name |
--qualifier | No | string | The 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*
| Parameter | Required | Type | Description |
|---|---|---|---|
--serviceName | Yes | string | The service name |
--qualifier | No | string | The service version or alias |
*Query parameters*
| Parameter | Required | Type | Description |
|---|---|---|---|
--limit | No | string | The maximum number of functions to return |
--nextToken | No | string | The pagination token from a previous response. Include this in subsequent requests to retrieve the next page of results. Omit on the first request |
--prefix | No | string | Filters results to functions whose names start with this prefix |
--startKey | No | string | Returns 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*
| Parameter | Required | Type | Description |
|---|---|---|---|
--serviceName | Yes | string | The service name |
--functionName | Yes | string | The function name |
--qualifier | No | string | The service version or alias |
*Body*
| Parameter | Required | Description |
|---|---|---|
--body | No | The payload data passed to the function |
*Header parameters*
| Parameter | Required | Description |
|---|---|---|
X-Fc-Invocation-Type | No | The invocation method. Valid values: Sync (synchronous) and Async (asynchronous) |
X-Fc-Log-Type | No | The 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-Id | No | The 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.