An HTTP trigger triggers the execution of a specific function by sending an HTTP request. The supported HTTP request methods include HEAD, POST, PUT, GET, and DELETE. HTTP triggers can be used in scenarios such as the fast construction of web services.

Benefits

Both HTTP triggers and API Gateway triggers can be used to create web applications. Compared with API Gateway triggers, HTTP triggers have the following benefits:

  • HTTP triggers simplify the learning and debugging processes for developers, and help developers quickly build web services and APIs by using Function Compute.
  • You can use HTTP testing tools that you are familiar with to validate the functionality and performance of HTTP triggers on Function Compute.
  • Request processing is streamlined. HTTP triggers support more efficient request and response formats. You do not need to encode or decode the request to JSON format while achieving better performance.
  • You can easily connect HTTP triggers to other services that support webhooks, such as Content Delivery Network (CDN) back-to-origin and Message Service (MNS).

Restrictions

  • After an HTTP trigger is set for a function, other types of triggers cannot be set for this function.
  • Each function can have only one HTTP trigger.
  • If versioning is enabled for a function, only one HTTP trigger can be created for each version or alias of the function. That is, one HTTP trigger can be created for one version or one alias of a function. For more information about versions and aliases, see Introduction of version management.
  • The following fields in a Request Headers key are ignored, and cannot be customized. Keys that start with x-fc- cannot be customized, either.
    • accept-encoding
    • connection
    • keep-alive
    • proxy-authorization
    • te
    • trailer
    • transfer-encoding
  • The following fields in a Response Headers key are ignored, and cannot be customized. Keys that start with x-fc- cannot be customized, either.
    • connection
    • content-length
    • content-encoding
    • date
    • keep-alive
    • proxy-authenticate
    • server
    • trailer
    • transfer-encoding
    • upgrade
    • content-disposition:attachment
      Note For security, when the default aliyuncs.com domain name of Function Compute is used, the server forcibly adds the content-disposition: attachment field to the response header. This field is used to download the returned result in the browser as an attachment. To remove this restriction, you must set a custom domain name. For more information, see Bind custom domains.
  • Limits on HTTP requests

    If a request exceeds any one of the following limits, the system returns status code 400 and error code InvalidArgument.

    • headers 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 of the query parameters, cannot exceed 4 KB.
    • body size: the total size of the HTTP request body cannot exceed 6 MB.
  • Limits on HTTP responses

    If a response exceeds any one of the following limits, the system returns status code 502 and error code BadResponse.

    • headers size: the total size of all keys and values in the headers cannot exceed 4 KB.
    • body size: the total size of the HTTP response body cannot exceed 6 MB.
  • Other instructions

    You can map different HTTP paths for HTTP functions by binding a custom domain name. For more information, see Bind custom domains. You can also use API Gateway, with the backend service type set to HTTP, and the HTTP function path configured as the backend service address to implement similar functions . For more information, see Use Function Compute as a backend service of API Gateway.

Function handler form

The handler settings of functions with HTTP triggers and that of common functions are different. The following figures compare a common function and a function with an HTTP trigger in Node.js and Python, respectively. If you are still using common interfaces after you set HTTP triggers, modify them in a timely manner.
  • Node.jscode_compare_js
  • Pythoncode_compare_py