Management
Cloud functions are pieces of code that run in the cloud, eliminating the need to manage servers. They can be written in development tools and deployed with a single click to execute backend code. In cloud development, cloud functions enable users to upload their business logic code and trigger the functions through invocations, facilitating backend business operations.
View Functions
You can use the following command to list all cloud functions and view their basic information:
tcb fn list
You will see output similar to the following:
Specifying the Return Count and Offset
By default, the fn list
command lists only the first 20 functions. If you have more functions and need to list additional ones, you can specify the data length (limit) and offset for the returned results using the following options:
-l, --limit <limit> The number of data items to return. Default is 20.
-o, --offset <offset> The data offset. Default is 0.
like:
# Retrieve Information for the First 10 Functions
tcb fn list -l 10
# Retrieve Information for Functions 3-22 (Inclusive)
tcb fn list -l 20 -o 2
Download Cloud Function Code
You can download cloud function code using the following command:
tcb fn code download <functionName> [destPath]
By default, function code is downloaded to functionRoot
using the function name as the storage folder. You can specify a custom folder path, and all function code files will be downloaded directly to the specified folder.
Trigger Function
You can trigger your cloud functions locally via Cloudbase CLI:
# Trigger app Function
tcb fn invoke app
# Trigger All Functions in the Configuration File
tcb fn invoke
View Function Details
The fn list
command mentioned earlier only displays basic function information. If you wish to view detailed function information, you can use the following command:
# View app Function Details
tcb fn detail app
Output
Status: Deployment completed
Code size (B): 1695
Environment variables (key=value): key=value
Function name: test
Handler: index.main
Memory configuration (MB): 256
Modified time: 2019-08-19 21:15:39
Environment Id: dev-xxx
Runtime: Nodejs10.15
Timeout (S): 20
Network configuration: None
Trigger:
myTrigger:{"cron": "0 0 2 1 * * *"}
Function code (Java functions and functions with entry point exceeding 1 MB will not be displayed):
'use strict';
exports.main = async (event, context, callback) => {
console.log(event);
return 'hello world'
};
Delete a Function
You can delete the function using the following command:
# Delete the app function
tcb fn delete app
# Delete all functions in the configuration file
tcb fn delete
Copy Function
You can quickly copy an existing function using the following command:
# Copy app function as app2 function
tcb fn copy app app2
When using the fn copy
command, you must specify the original function name and the new function name after copying. The current environment ID and target environment ID are optional. If the target environment ID is not specified, the function will be copied to the current environment.
If the new function name already exists, the copy operation will be terminated. If you wish to overwrite the existing function, you can use the following command:
Overwriting Functions with the Same Name
# Copy app function as app2 function, overwriting the existing app2 function if it exists
tcb fn copy app app2 --force
Note: The copy function operation will not copy the function's triggers.