This topic describes the methods and limits of function invocations in Custom Container runtimes and provides sample code.
Background
Custom Container runtimes support the hosting of HTTP servers. The system converts function invocation requests into HTTP requests, sends the requests to HTTP servers, converts responses of the HTTP servers into the responses of the function invocations, and then returns the responses to clients. The following figure shows the process.
Functions can be invoked by using one of the following methods:
HTTP calls (recommend): Functions can be invoked by using HTTP calls. For example, you can invoke a function by using an HTTP trigger or a custom domain name.
API calls: You can invoke a function by calling the InvokeFunction operation. For example, you can invoke a function by using an SDK or trigger a function by using an event source.
The formats of the requests and responses of HTTP servers vary based on the invocation method.
Limits
Only one HTTP trigger can be created for an HTTP function in each version or alias of a service. For more information, see Manage versions and Manage aliases.
Limits on HTTP requests
You cannot use a custom request header that starts with x-fc- or the following custom request headers:
connection
keep-alive
Function Compute returns the
400
status code andInvalidArgument
error code if a request exceeds one of the following limits:Header size: The total size of all keys and values in the headers cannot exceed 4 KB.
Path size: The total size of the path, including all query parameters, cannot exceed 4 KB.
Body size: The total size of the body of a synchronous invocation request cannot exceed 32 MB. The total size of the body of an asynchronous invocation request cannot exceed 128 KB.
Limits on HTTP responses
You cannot use a custom response header that starts with x-fc- or the following custom response headers:
connection
content-length
date
keep-alive
server
content-disposition:attachment
NoteFor security reasons, if you use the default domain name aliyuncs.com of Function Compute, the server forcibly adds the content-disposition: attachment response header. This response header is used to download the returned results from the browser as an attachment. To remove this limit, you must configure a custom domain name. For more information, see Configure a custom domain name.
If a response exceeds the following limit, Function Compute returns the
502
status code andBadResponse
error code:Header size: The total size of all keys and values in the headers cannot exceed 4 KB.
Others
You can bind custom domain names to map different HTTP paths for HTTP functions. For more information, see Configure a custom domain name. You can also use API Gateway to implement similar features by setting the backend service type to HTTP and specifying the HTTP function path as the backend service address. For more information, see Use Function Compute as the backend service of an API operation.