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 Services and Functions. In the Services pane, click the service that you require.
  4. On the Services and Functions page, click the service that you require. Then, click the Versions tab.
    version
  5. On the Versions tab, find the version for which you want to create an alias and click Create alias in the Actions column.
    Create alias
  6. In the Create alias dialog box, set the parameters and click OK.
    alias-information

    The following table describes the parameters.

    Parameter Required Description Example
    Alias name Yes The name of the alias. alias
    Description No The description of the alias. N/A
    Version No The version for which you want to create the alias. You do not need to set this parameter. 1
    Additional version ID No To route some requests to a canary release version for processing, you can select the canary release version from the Additional version ID drop-down list. 2
    Weight No To route some requests to a canary release version for processing, you must set this parameter. Enter the weight of the canary release version. 30
    On the Versions tab, click Alias. You can view the created alias. In this example, the alias points to version 1, the canary release version is version 2, and the weight of the canary release version is 30%.result-alias

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

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

This topic describes how to use an alias in an Object Storage Service (OSS) event trigger.

Note A trigger has no version but can point to a specific service version or alias.
  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Services and Functions. In the Services pane, click the service that you require.
  3. On the Functions tab, click the name of the function that you require.
  4. On the details page of the function, click the Triggers tab.
  5. In the trigger list, click the name of the trigger that you require.
  6. In the Edit Trigger panel, change the value of the Version/Alias parameter from LATEST to the alias that you created. Then, click OK.
    change-version

Step 3: Invoke the function associated with the specified alias

You can verify whether the function for the service of the correct version is executed in the Function Compute console or by calling the API operation.

Invoke the function associated with the specified alias in the Function Compute console

  1. On the Service/Function page, find the target service named service.
  2. Click the name of the function that you require.
  3. In the upper-right corner of the details page of the function, select Service Alias from the Service Version drop-down list, and select an alias from the Alias drop-down list.
    choose-version
  4. Click the Code tab.
  5. Click Invoke.
    After the function is executed, you can view the execution log in the lower part of the page. In the log, you can see that the value of the qualifier parameter that indicates the version information is PROD and the versionId parameter that indicates the version ID is 1. The log shows that the executed function belongs to the service associated with the alias PROD and the alias points to version 1.result-alias

Invoke the function associated with the specified alias by calling the API operation

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

POST /services/{serviceName}.{qualifier}/functions/{functionName}/invocations           
The sample request is as follows:
POST /services/{service}.{qualifier}/functions/{function}/invocations
The following API operations support similar usage:

Step 4: Publish a canary release version

After a new version is developed, you must use a canary release 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 Alias.
  3. In the alias list, find the 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 ID parameter to the new version and enter the weight of the canary release version in the Weight field. Click OK.
    set-additional-version
    After the configuration is complete, 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 canary release version becomes stable, you can switch all online traffic to the service of the new version.

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