This topic shows you 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 in the service of the LATEST version until the service becomes stable.

  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 set the alias to point to the version. When this version is updated, you need only to change the version to which the alias points to the new version. This way, the caller does not need to know the specific version of the service, but need only to use the correct alias. If a trigger is created for your function, you need only to associate the trigger with the alias. Changing the version does not affect the use of the trigger.

View the version for a function

To view the version or alias for a running function, add the following code to the function. In this example, the code is written in Node.js.
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 following part describes the parameters in the preceding code:
  • qualifier: the version information that is passed in when the function is invoked. It can be a version number or an alias.
  • versionId: the specific version number that is parsed out based on the qualifier when the function is executed.