Function type selection

更新时间:
复制 MD 格式

Function Compute provides two function types: event functions and HTTP functions. Your choice determines the handler signature and how your function is triggered, so pick the right type before writing code.

A handler consists of three parts: the function name, the function input parameters, and responses. You can also pass another function defined in the code as an input parameter to the handler.

How the types differ

FeatureEvent functionsHTTP functions
Trigger methodTimers, API/SDK calls, and triggers from other Alibaba Cloud services (OSS, Log Service, Alibaba Cloud CDN, Tablestore, EventBridge, and more)HTTP or HTTPS requests only
Supported triggersAll trigger typesHTTP triggers only (one per version or alias)
Handler parametersevent, context, callbackrequest, response, context
Best forEvent-driven pipelines and integrationsWeb applications and APIs

Event functions

An event function runs in response to an event from a timer, an API or SDK call, or a trigger from another Alibaba Cloud service. All supported trigger types work with event functions.

Use when you need to:

  • Process files after they are uploaded to Object Storage Service (OSS)

  • Run scheduled jobs with a timer trigger

  • React to log entries, CDN events, or messages from EventBridge

  • Handle any event-driven workflow that does not require direct HTTP access

Handler signature (Node.js):

exports.handler = function(event, context, callback) {
  callback(null, 'hello world');
}
ParameterDescription
eventThe event data passed to the handler. Convert it to the appropriate type based on your business requirements.
contextRuntime information provided by Function Compute, including request IDs and temporary keys.
callbackThe function to call when returning invocation results.

For Node.js event function details, see Event handlers. For other programming languages, see Programming model overview.

HTTP functions

An HTTP function is triggered exclusively by HTTP or HTTPS requests. It accepts standard HTTP request methods (GET, POST, PUT, DELETE, HEAD, PATCH) and gives you direct access to the request and response objects — no intermediate event format conversion needed.

Note

Each version or alias of a service supports only one HTTP trigger.

Use when you need to:

  • Build RESTful APIs or web backends

  • Migrate an existing web framework (Express, Koa, or similar) to the cloud

  • Handle HTTP requests directly without going through an event format layer

Handler signature (Node.js):

exports.handler = function(request, response, context) {
  response.send(null, 'hello world');
}
ParameterDescription
requestThe HTTP request, including headers (key-value pairs), the request method, and the client IP address.
responseThe HTTP response, including headers (key-value pairs) and the response body.
contextRuntime information provided by Function Compute, including request IDs and temporary keys.

For Node.js HTTP function details, see HTTP handlers. For other programming languages, see Programming model overview.

What's next