This document describes how to quickly create and use a web function in the SCF console.
Before using SCF, you need to sign up for a Tencent Cloud account and complete identity verification first.
WebFunc
in the search box to filter all web function templates, select the one you want to use, and click Next as shown below:scf_bootstrap
bootstrap file for your project to ensure that the web server can be started properly in the function environment. You can select the default framework template provided by SCF or use a custom template to write your own start command. For more information, please see Bootstrap File Description.You can open the access path URL in a browser, and if it can be accessed normally, the function is successfully created.
For web functions, the returned body information of each request will not be automatically reported to the log. You can customize the reporting in the code through statements such as console.log()
or print()
in your programming language.
For PHP, as all inputs are automatically used as the body, you need to run the following command to output the log to stdout
and complete log reporting:
<?php
$stdout = fopen("php://stderr","w");
fwrite($stdout,"123\n");
?>
On the details page of a created function, select Log Query to view its detailed logs. For more information, please see Viewing Execution Logs.
On the details page of a created function, select Monitoring Information to view metrics such as function invocations and execution duration. For more information, please see Monitoring Metric Descriptions.
Note:The minimal granularity of monitoring statistics collection is 1 minute. You need to wait for 1 minute before you can view the current monitoring record.
Common errors are divided into two types: user errors and platform errors.
The table below describes the possible scenarios of request errors and function errors, so that you can quickly troubleshoot problems. For more information on error codes, please see Function Status Code.
Status Code | Return Message | Description |
---|---|---|
200 | Success | The function is executed successfully. If you see this return code, but the returned information does not meet your expectations, check whether your code logic is correct. |
Status Code | Return Message | Description |
---|---|---|
404 | InvalidSubnetID | The subnet ID is invalid. Check whether the network configuration of the function is correct and whether the subnet ID is valid. |
405 | ContainerStateExitedByUser | The container process exits normally. Check whether your bootstrap file is correctly written. |
406 | RequestTooLarge | The request body size is too large. The upper limit for sync request events is 6 MB. |
410 | The HTTP response body exceeds the size limit. | The size of function response body exceeds the upper limit of 6 MB. Adjust it and try again. |
430 | User code exception caught | A user code execution error occurs. Based on the error log on the console, check the error stack of the code and see whether the code can be executed properly. |
433 | TimeLimitReached | The function execution times out. Check whether a large number of time-consuming operations exists in the service code or adjust the timeout period on the Function Configuration page. |
439 | User process exit when running | The user process exits accidentally. Based on the error message, find out the cause and fix the function code. |
446 | PortBindingFailed | No listening port is specified. Check whether your business code listens on port 9000 . |
499 | kRequestCanceled | The user manually interrupts the request. |
Status Code | Return Message | Description |
---|---|---|
500 | InternalError | An internal error occurs. Try again later. If the problem persists, submit a ticket. |
When debugging in a local container, in order to ensure consistency with the standard container environment in the cloud, you need to pay attention to the limits of readable and writable files in the local environment. The local container startup command is as follows:
docker run -ti --read-only -w /var/user \
-v /usr/local/cloudfunction/runtime:/var/runtime:ro \
-v ${PWD}:/var/user:ro \
-v /tmp:/tmp \
-v /usr/local/cloudfunction/runtime:/var/runtime:ro \
-v /usr/local/cloudfunction/lang:/var/lang:ro \
ccr.ccs.tencentyun.com/cloudfunc/qcloud-func bash
Was this page helpful?