Cloud Native 9 min read

Enable Asynchronous Calls for Alibaba Cloud Function Compute HTTP Triggers

This guide explains how to use the new asynchronous invocation feature of Alibaba Cloud Function Compute HTTP triggers, covering the limitations of synchronous calls, the required request header, testing methods, and a best‑practice video‑transcoding example with step‑by‑step commands.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Enable Asynchronous Calls for Alibaba Cloud Function Compute HTTP Triggers

Background and Limitations

Alibaba Cloud Function Compute provides two function types: event functions and HTTP functions . HTTP functions paired with an HTTP trigger let users call functions via RESTful APIs without integrating the SDK. However, HTTP functions were originally designed for web scenarios and do not support asynchronous invocation, which creates problems for long‑running tasks such as video transcoding, file processing, or load‑testing.

Problems of Synchronous HTTP Functions

Long‑running functions increase error risk because clients must keep a long‑lived connection; network fluctuations or client impatience can cause disconnections.

Maintaining long connections consumes client resources and reduces efficiency.

Burst traffic (e.g., pulse‑style load tests or flash sales) can be throttled, leading to request failures when the client does not handle errors.

Scenario: a video‑upload service where transcoding takes minutes; the page refreshes and the connection drops, causing the transcoding to fail.

Work‑around Before Async Support

Users previously created two functions: an HTTP function (synchronous) that called an event function via the SDK to achieve asynchronous behavior. This approach has clear drawbacks:

Higher cost: each async call requires two triggers.

No full flow control: the first layer remains synchronous, so burst traffic still needs client‑side throttling.

Increased development effort: developers must maintain two functions.

New Feature: HTTP Trigger Supports Asynchronous Invocation

The platform now allows asynchronous calls directly from an HTTP trigger. To enable it, add the request header X-Fc-Invocation-Type: Async. If the header is omitted, the default is synchronous.

Testing the Async Call

Console test: enable the “Async Invocation” option when configuring the function test page.

cURL test:

curl -v -H "X-Fc-Invocation-Type: Async" https://http-***.cn-shenzhen.fcapp.run/$path

Successful async requests return HTTP status 202 and include a request ID in the response headers. The request ID can be used to query execution logs in the console or to monitor the async task list.

Best‑Practice Example: Video Transcoding via HTTP Trigger

This example shows how to combine Serverless Devs and the console to build an async video‑transcoding workflow.

Prerequisites

Install Serverless Devs (see documentation).

Configure Serverless Devs.

Create an OSS bucket for input/output files.

Create a RAM role with OSSFullAccess (or use AliyunFCDefaultRolePolicy).

Step‑by‑Step Operations

Initialize the project:

s init http-video-transcode -d http-video-transcode

Enter the project directory and deploy: cd http-video-transcode && s deploy Invoke the function asynchronously via HTTP trigger:

curl -v -H "X-Fc-Invocation-Type: Async" -H "Content-Type: application/json" -d '{"bucket":"my-bucket","object":"480P.mp4","output_dir":"a","dst_format":"mov"}' -X POST https://http-***.cn-shenzhen.fcapp.run/

Log in to the console to check task status and manage the task.

Configure callback functions (e.g., dest‑fail or dest‑succ) to handle transcoding results.

Callback documentation: https://help.aliyun.com/document_detail/422720.html

Conclusion

Supporting asynchronous invocation for HTTP triggers removes the last barrier for using Function Compute as a fully managed platform to build web services, providing an out‑of‑the‑box, low‑cost, and easy‑to‑monitor solution for long‑running and burst‑traffic workloads.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeServerlessAlibaba CloudFunction ComputeAsync InvocationHTTP Trigger
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.