Function Layer Management
The SCF Layer (Layer) allows you to package common dependencies or shared code separately and mount them to multiple functions, avoiding repeated uploads and reducing the size of individual functions.
Layer Limitations
- A single user can create up to 20 layers
- Each function can be bound to a maximum of 5 layers
- Single layer should not exceed 100 MB
- Layer versions cannot be modified; updating the content requires publishing a new version.
tcb fn layer create
Create a new layer (release a new version).
tcb fn layer create <alias> --file <path> [options]
Parameters
| Parameter | Description | Required |
|---|---|---|
alias | Layer alias | ✅ |
--file <path> | File directory or ZIP file path | ✅ |
--runtime <runtimes> | Compatible runtimes, comma-separated (defaults to mainstream runtimes if not specified) | — |
-e, --env-id <envId> | Environment ID | ✅ |
Example
# Upload Directory
tcb fn layer create myLayer --file ./node_modules -e my-env-id
# Upload ZIP file and specify compatible runtimes
tcb fn layer create commonLib --file ./libs.zip --runtime Nodejs18.15,Nodejs20.19 -e my-env-id
tcb fn layer list
View the layer list or view layers bound to a function.
tcb fn layer list [options]
Parameters
| Parameter | Description |
|---|---|
--name <functionName> | View layers bound to the specified function |
--layer <layerAlias> | View all versions of the specified layer |
--code-secret <secret> | CodeSecret required to access the code encryption function |
-e, --env-id <envId> | Environment ID |
Example
# View all layers of the current environment
tcb fn layer list -e my-env-id
# View layers bound to the specified function
tcb fn layer list --name myFunc -e my-env-id
# View all versions of a layer
tcb fn layer list --layer myLayer -e my-env-id
tcb fn layer bind
Bind layers to SCF.
tcb fn layer bind <functionName> [options]
Parameters
| Parameter | Description |
|---|---|
--layer <layerAlias> | Layer alias to bind (specify to skip interactive selection) |
--layer-version <version> | Layer version number (used with --layer) |
--code-secret <secret> | CodeSecret (for code encryption functions) |
-e, --env-id <envId> | Environment ID |
Example
# Interactive Layer Binding Selection
tcb fn layer bind myFunc -e my-env-id
# Directly specify layer and version (skip interaction)
tcb fn layer bind myFunc --layer myLayer --layer-version 3 -e my-env-id
tcb fn layer unbind
Unbind layers from SCF.
tcb fn layer unbind <functionName> [options]
Parameters
| Parameter | Description |
|---|---|
--layer <layerAlias> | Layer alias to unbind (if empty, will trigger interactive selection) |
--code-secret <secret> | CodeSecret (for code encryption functions) |
-e, --env-id <envId> | Environment ID |
Example
tcb fn layer unbind myFunc --layer myLayer -e my-env-id
tcb fn layer sort
Rearrange the loading order of layers bound to the function (the order affects the override priority of files with the same name).
tcb fn layer sort <functionName> [options]
Parameters
| Parameter | Description |
|---|---|
--code-secret <secret> | CodeSecret |
-e, --env-id <envId> | Environment ID |
Example
tcb fn layer sort myFunc -e my-env-id
tcb fn layer download
Download the content files of the layer to local.
tcb fn layer download [options]
Parameters
| Parameter | Description |
|---|---|
--dest <path> | Download path for saving files (if left blank, selected interactively) |
-e, --env-id <envId> | Environment ID |
Example
tcb fn layer download --dest ./downloaded-layer -e my-env-id
tcb fn layer delete
Delete the specified layer (interactively select the version).
tcb fn layer delete [options]
Example
tcb fn layer delete -e my-env-id
Note
After deleting all versions of the layer, the layer will be completely removed. Functions bound to this layer must be unbound before deletion.