When you invoke a function asynchronously, Function Compute queues the request and returns a response immediately — without waiting for execution to complete. Configure a destination to route invocation results to a downstream service automatically. Function Compute sends the result context to the destination after each invocation succeeds or exhausts all retry attempts.
How it works
Use cases
Retain discarded events for further processing: If an asynchronous invocation fails after all retry attempts, Function Compute discards the event. Configure a failure destination to forward the invocation context to a message service — such as ApsaraMQ for RocketMQ — for analysis or reprocessing. Alternatively, set another function as the destination to run custom error-handling logic.
Notify downstream services of invocation results: After a successful invocation, Function Compute sends the request context to the configured success destination. For example, if you use Function Compute to decompress ZIP files uploaded to OSS, configure a success destination to trigger a notification when the job completes.
Supported destinations
Function Compute supports the following services as destinations for asynchronous invocations. You can configure destinations per function, per version, and per alias.
Only event functions can be configured as destinations. HTTP functions are not supported. For more information, see Select a function type.
| Destination service | Required permission | Payload limit |
|---|---|---|
| Simple Message Queue (formerly MNS) | mns:SendMessage or mns:PublishMessage | 64 KB |
| Function Compute | fc:InvokeFunction | 128 KB |
| EventBridge | eventbridge:PutEvents | 64 KB |
| ApsaraMQ for RocketMQ | mq:PUB | 4 MB |
Simple Message Queue (formerly MNS) and EventBridge have a 64 KB payload limit. If the invocation payload approaches this limit, delivery may fail. For large payloads, use ApsaraMQ for RocketMQ (4 MB limit) instead.
Event payload sent to the destination
Simple Message Queue (formerly MNS), Function Compute, and ApsaraMQ for RocketMQ
Function Compute passes the following JSON as the message body or function payload:
{
"timestamp": 1660120276975,
"requestContext": {
"requestId": "xxx",
"functionArn": "acs:fc:::services/{serviceName}/functions/{functionName}",
"condition": "FunctionResourceExhausted",
"approximateInvokeCount": 3
},
"requestPayload": "",
"responseContext": {
"statusCode": 200,
"functionError": ""
},
"responsePayload": ""
}| Parameter | Description |
|---|---|
timestamp | The timestamp of the invocation. |
requestContext | The context of the request. |
requestContext.requestId | The request ID of the asynchronous invocation. |
requestContext.functionArn | The ARN of the asynchronously invoked function. |
requestContext.condition | The invocation error code. |
requestContext.approximateInvokeCount | The number of times the invocation was attempted. A value greater than 1 means Function Compute retried the function. |
requestPayload | The original payload of the function request. |
responseContext | The response context. |
responseContext.statusCode | The system-level return code of the function invocation. A non-200 value indicates a system error. |
responseContext.functionError | The invocation error message. |
responsePayload | The raw payload returned by the function execution. |
EventBridge
Function Compute passes the invocation record as the data field in the event. For more information about the event format, see Event overview.
{
"datacontenttype": "application/json",
"aliyunaccountid": "143xxxx",
"data": {
"requestContext": {
"condition": "",
"approximateInvokeCount": 1,
"requestId": "0fcb7f0c-xxxx",
"functionArn": "acs:fc:::services/xxxx.LATEST/functions/xxxx"
},
"requestPayload": "",
"responsePayload": "",
"responseContext": {
"functionError": "",
"statusCode": 200
},
"timestamp": 1660120276975
},
"subject": "acs:fc:::services/xxxx.LATEST/functions/xxxx",
"source": "acs:fc",
"type": "fc:AsyncInvoke:succeeded",
"aliyunpublishtime": "2021-01-03T09:44:31.233Asia/Shanghai",
"specversion": "1.0",
"aliyuneventbusname": "xxxxxxx",
"id": "ecc4865xxxxxx",
"time": "2021-01-03T01:44:31Z",
"aliyunregionid": "cn-shanghai-vpc",
"aliyunpublishaddr": "199.99.xxx.xxx"
}The type field is set to fc:AsyncInvoke:succeeded for successful invocations.
Configure a destination
Prerequisites
Before you begin, ensure that you have:
Granted the function's service role the required permission to access the destination service (see the Supported destinations table above). For setup instructions, see Grant Function Compute permissions to access other cloud services
Configure a success or failure destination
Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.
In the top navigation bar, select a region. On the Services page, click the desired service.
On the Functions page, click the name of the target function. On the function details page, click the Asynchronous Configurations tab.
Configure the destination:
For successful invocations: In the Destination for Successful Invocation section, click Modify. In the panel, set Invoke Other Services upon Success to Enable, then configure the destination service.
For failed invocations: In the Destination for Failed Invocation section, click Modify. In the panel, set Invoke Other Services upon Failure to Enable, then configure the destination service.
Configure the parameters for the selected destination service:
Destination service Parameters Function Compute Service Name, Version or Alias, Function Name. Only event functions are supported. Simple Message Queue (formerly MNS) Destination Type (Queue or Topic), then Queue name or Topic name. Queue delivers to one consumer; Topic uses publish-subscribe for multiple consumers. ApsaraMQ for RocketMQ Instances (select the instance), Topic (select the topic). EventBridge Custom Event Bus (specify the event bus name). Click OK.
Avoid circular invocations. For example, if Function B is the success destination for Function A, and Function A is the success destination for Function B, a successful invocation of either function triggers an infinite loop.
Handle callback failures
A destination callback may fail if the service role lacks permissions or the destination service is unavailable. Function Compute retries or records an error depending on the HTTP status code:
| Error code | Cause | System behavior |
|---|---|---|
| 5xx | Throttling, content errors, or other transient issues | Retries with exponential backoff. Initial retry interval: 500 ms. Maximum retry duration: 30 minutes. |
| 4xx | Insufficient permissions, incorrect parameters, deleted resource, or payload exceeds the destination limit | Returns an error and records the error message. |
Monitor destination invocations
If a callback fails, Function Compute records the failure in monitoring metrics. To view them:
Log on to the Function Compute console.
In the left-side navigation pane, choose Advanced Features > Monitoring.
In the Service Name list, click the name of the destination service.
The following metrics are available for destinations:
| Metric | Metric ID | Description |
|---|---|---|
| Destination invocation errors | FunctionDestinationErrors | Number of failed destination callback requests. Aggregated at 1-minute or 1-hour granularity. |
| Destination invocation successes | FunctionDestinationSucceed | Number of successful destination callback requests. Aggregated at 1-minute or 1-hour granularity. |
For a full list of monitoring metrics, see Monitoring metrics.
What's next
Configure destinations using the API or Serverless Devs: see API Reference and Common Serverless Devs commands.
Learn how HTTP functions handle invocations: see HTTP invocation methods.
Enable asynchronous task mode for additional control over async invocations: see Asynchronous tasks.