After a version is created, you can use an alias to manage the version. The caller can call the correct service version by using the alias without knowing the service version.

Step 1: Create an alias

  1. Log on to the Function Compute console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Service/Function.
  4. Click the target service named service, and then click the Versions tab.
  5. In the version list, find the version for which you want to create an alias. Then, click Create Alias in the Actions column.
    create-alias
  6. In the Create Alias dialog box, modify the alias and click OK.
    Click the Alias tab. You can see the created alias named alias and version 1 to which the alias points.result-alias

(Optional) Step 2: Use the alias in a trigger

If you have created a trigger for your function, you can associate the trigger with the alias. In this way, when the online version is switched, the trigger will not be affected and can be smoothly switched to the version to which the alias points.

This topic uses an Object Storage Service (OSS) trigger as an example to describe how to use an alias in a trigger.

Note A trigger has no version but can point to a specific service version or alias.
  1. In the upper-right corner of the function list, select LATEST from the Service Version drop-down list. Then, click the target function name.
  2. On the function details page, click the Triggers tab.
  3. In the trigger list, click the target trigger name.
  4. On the Edit Trigger page, change the value of Version/Alias from LATEST to the alias that you created. Click OK.
    change-version

Step 3: Run the function associated with the specified alias

In the Function Compute console or by calling the Function Compute API, you can verify whether the function for the service of the correct version is executed.

Run the function associated with the specified alias in the Function Compute console
  1. Click the target function name.
  2. In the upper-right corner of the function details page, select PROD on the Alias tab from the Service Version drop-down list.
    choose-version
  3. Click the Code tab.
  4. Click Invoke.
    After the function code is executed, you can view the execution log at the lower part of the page. In the log, you can see that the value of the qualifier field that indicates the version information is PROD and the versionId field that indicates the parsing result is 1. The log shows that the executed function belongs to the service associated with alias PROD and the alias points to version 1.result-alias
Run a function associated with a specified alias by calling the Function Compute API

To enable the system to run a function associated with a specified alias, you can append a period (.) as a separator to serviceName in the request path and use qualifier to specify the alias. The request is in the following format:

POST /services/{serviceName}.{qualifier}/functions/{functionName}/invocations           

Step 4: Publish an additional version

After a new version is developed, you need to use an additional version to ensure that the new version is stable.

  1. Publish a new version. For more information, see Publish a version.
    After the version is published, you can view the newly published version in the version list.version2
  2. On the Versions tab, click the Alias tab.
  3. In the alias list, find alias PROD that points to version 1 and was created in Step 1. Then, click Update Alias in the Actions column.
  4. In the Update Alias dialog box, set the additional version to the new version and enter the weight of the additional version. Click OK.
    set-additional-version
    After the configuration is completed, the specified percentage of the traffic is switched to the service of the new version.

Step 5: Switch all traffic to the new version

After the additional version runs stably, you can switch all online traffic to the service of the new version.

  1. On the Versions tab, click the Alias tab.
  2. In the alias list, find alias PROD that points to version 1 and additional version 2 published in Step 4. Then, click Update Alias in the Actions column.
  3. In the Update Alias dialog box, set the major version to the new version and leave Additional Version ID empty. Click OK.
    publish-version2
    After the configuration is completed, all of your online traffic is switched to the service of the new version.