This topic describes how a flow in Serverless workflow schedules reserved resource functions or functions with specified versions.


In actual production scenarios, functions scheduled by the task flow may frequently change due to changes in service scenarios. Therefore, you must avoid unexpected actions caused by the changes and control the stability of the task flow. In the following scenarios, functions of a fixed version will help in Serverless workflow task steps:

  • Flow A orchestrates multiple functions f1, f2, and f3. The same task must execute the same version of the functions. For example, when flow A is under execution, function f1 has been executed, but the function is updated at this time. In this case, the latest versions of functions f2 and f3 may be executed in flow A, which may cause unexpected results. Therefore, the version of the functions that the flow executes must be fixed.
  • A function needs to be rolled back. If you find that the flow failed due to a new change after the function is launched, you must roll back the flow to the previous fixed version.
  • The function alias is used to call a reserved resource function, reduce the function cold start time, and Best practice for cost optimization.

Functions of different Introduction to versions that are deployed in Function Compute can efficiently support continuous integration and release in similar scenarios. The following section uses an example to describe how to use the function alias in the flow to call a reserved resource function. Reserved resource functions depend on the functions of a specified version. You can see this example in scenarios where functions of specified versions are required.

Step 1: Create a reserved instance for a function

Create a service named fnf-demo in Function Compute. In this service, create a Python 3 function named provision and release its version and alias to generate a reserved instance. For more information, see Introduction to supplementary examples.

Assume that the version of the created function is 1, the alias is online, and a reserved instance is generated. The following code shows the content of the function:

import logging

def handler(event, context):
  logger = logging.getLogger()'Started function test')
  return {"success": True}           

Step 2: Create a flow

Serverless workflow natively supports the versions and aliases of functions in Function.

In the task step of Serverless workflow, enter the default value acs:fc:{region}:{accID}:services/fnf/functions/test in the resourceArn parameter. Based on the function execution rule, the function of the latest version is executed by default. You can release the Manage versions or Manage aliases and enter acs:fc:{region}:{accID}:services/fnf.{ alias or version}/functions/test in the resourceArn parameter of the task step in the flow to call the function of the specified version. Therefore, define the flow based on the following code:

version: v1
type: flow
  - type: task
    resourceArn: acs:fc:::services/
    # You can also use the version by defining resourceArn: acs:fc:::services/fnf-demo.1/functions/provision.
    name: TestFCProvision          

Step 3: Execute the reserved function and check the execution result in the console or on a CLI

  1. Execute the flow. The following figure shows the execution details before the reserved mode is used.1
  2. The following figure shows the execution details after the reserved mode is used.2

As shown in the figures, after the reserved mode is used, the flow execution time is reduced from 500 ms to 230 ms.