This example shows how to manage versions by using the version management feature of Function Compute.

Version management process

  1. Prepare a function

    When you create a service and its function for the first time, the version of the service is LATEST. You can debug the function for the service of the LATEST version until the function runs stably.

  2. Publish a version

    When the service of the LATEST version becomes stable, you can publish the service of this stable version to serve online requests.

  3. Switch traffic by using an alias

    After a version is published, you can create an alias and point the alias to the version. When this version is updated, you only need to change the version to which the alias points to the new version. In this way, the caller is freed from needing to know the specific version of the service, but only need to use the correct alias. If a trigger is created for your function, you only need to associate the trigger with the alias. Changing the version does not affect the use of the trigger.

View the version of a function

To view the version or alias used in a running function, add the following code to the function. In this example, the code is written in the Node.js language.
module.exports.handler = function(eventBuf, context, callback) {
    var qualifier = context['service']['qualifier']
    var versionId = context['service']['versionId']
    console.log('Qualifier from context:', qualifier);
    console.log('VersionId from context:', versionId);
    callback(null, null);
The definitions of some parameters in the code are as follows:
  • qualifier: indicates the version information that is passed in when the function is called. It can be a version number or an alias.
  • versionId: indicates the specific version number that is parsed out based on the qualifier during function execution.