Cloud Function Operation Guide
1. Write Cloud Function
For local development of Cloud Function 2.0, refer to the following documents:
2. Deploy Cloud Function
2.1. Download Custom Code Deployment and Upload Tool
You need to download the Cloud Function deployment and upload tool private-cloud-function (abbreviated as pcf).
# 1. linux system
## 1.1 Download URL: https://software-1302110647.cos.ap-guangzhou.myqcloud.com/rc/lastest/tools/amd64/linux/pcf
## 1.2 Make it executable:
chmod +x pcf
# 2. windows system
## 2.1 Download URL:
https://software-1302110647.cos.ap-guangzhou.myqcloud.com/rc/lastest/tools/amd64/windows/pcf.exe
# 3. macOS system
## 3.1 Download URL:
https://software-1302110647.cos.ap-guangzhou.myqcloud.com/rc/lastest/tools/amd64/macOS/pcf
## 3.2 Make it executable:
chmod +x pcf
For Windows systems, you can press win+r to open the Command Prompt. Download the Windows command-line tool pcf.exe: when executing, replace ./pcf with .\pcf.exe (Please run it in the command line's current directory).
2.2. Add login information
"aliasname is an alias for host. If not specified, it defaults to the default host 'default' [weda access URL; different hosts represent different weda environments]
./pcf add-host <alias> --host=<login URL> --username=<username> --password=<password>
# For example: ./pcf add-host --host=http://192.135.35.80 --username=admin --password="Weda@xxx"
2.3. Upload Cloud Function
funcname is the identifier of the function
./pcf func push <funcname> --alias=<aliasname> --path=<code path>
# Example: Download the repository from https://github.com/TencentCloudBase/func-v2-template. After passing local tests, deploy it by running the following command:
# ./pcf func push test1 --path="/data/code/func-v2-template"
2.4. Publish Cloud Function
./pcf func deploy <funcname> --alias=<aliasname>
# Returns: deployment success or failure
## Example: funcname is test1
# ./pcf func deploy test1
3 Invoking Cloud Functions in APIs
3.1. Select APIs Type
Select HTTP Request as the APIs method request type
3.2. Create APIs Method
1) URL: Enter http://func-server:3000
2) Method: Select the method corresponding to the interface you have written, e.g., POST/GET, etc. (depending on the method defined in the cloud function code)
3.3. Method Testing
4. Other Subcommands Usage
4.1. Delete login information
./pcf del-host <aliasname>
4.2. List Cloud Functions
./pcf func list --alias=<aliasname>
# Return: Returns a function list. Note that only one function can be active [published, while others remain unpublished]
4.3. Deleting Cloud Function
./pcf func del <funcname> --alias=<aliasname>
5 Troubleshooting
5.1. View Service-Level Logs
If a cloud function has syntax errors, it will throw an error in version 2.5.3 after deployment. In this case, you need to check the logs of the func-server container:
Standalone Edition:
View error logs
docker logs -f -n 100 func-sevrer
Cluster Edition:
kubectl -nsoftware logs -f --tail=100 <func-server>
### The specific name of func-server can be viewed using the following command:
kubectl -nsoftware get po | grep func-server
For example: Errors such as syntax issues or missing dependencies occur. This error indicates missing dependencies. You need to run the code locally before uploading it (ensuring dependencies are downloaded):
5.2. View User-Level Logs
Log in to the func-server container and check the following two directories:
/workspace/logs/accesslog*.log
/workspace/logs/usercodelog*.log
How to access the container?
- Standalone Edition:
docker exec -it func-server bash
- Cluster Edition:
### 1. First: The specific name of func-server can be viewed using the following command:
kubectl -nsoftware get po | grep func-server
### 2. Execute:
kubectl -nsoftware exec -it <the name obtained in step 1> -c func-server bash