Web function is a function type in SCF. Compared with event function that has limits on the event format, web function focuses on optimization of web service scenarios and can directly send HTTP requests to URLs to trigger function execution.
In terms of the support for web service scenarios, web function excels event function in the following aspects:
Koa, to write web functions. You can also quickly migrate your local web framework services to the cloud with minimal modification.
How a web function works is as shown below:
After your HTTP request passes API Gateway, when directly passing through the native request, API Gateway will add the content required by the gateway to trigger the function, such as function name and function region, to the request header and pass the modified request to the function environment to trigger the backend function.
In the function environment, the built-in proxy is used to implement Nginx-based forwarding, remove the request information not required by the service specification from the header, and send the native HTTP request to your web server service through the specified port.
After being configured with the specified listening port
9000 and service bootstrap file, your web server will be deployed in the cloud and use this port to get HTTP requests for processing.
/tmpdirectory is readable and writable. When outputting files, please select the
/tmppath; otherwise, the service will exit exceptionally due to the lack of write permission.
Response headershas the following limits:
valuevalues cannot exceed 4 KB.
bodycannot exceed 6 MB.
9000port and cannot listen on the internal loopback address
Connectionfield in the HTTP request header cannot be customized.
The common request headers received by your web server from the function environment are as detailed below, none of which can be customized:
|X-Scf-Request-Id||Current request ID|
|X-Scf-Memory||Maximum memory that can be used during function instance execution|
|X-Scf-Timeout||Timeout period for function execution|