When you update a function in Function Compute, the new code and configurations overwrite the LATEST version immediately, and all subsequent invocations run against this updated version. Releasing changes directly to all traffic carries risk in production environments.
The community-provided @serverless-cd/fc-canary plugin lets you perform canary release by routing only a specified percentage of traffic to the new version before promoting it fully.
How it works
Function Compute uses aliases to separate deployments from releases. In production, you point an alias to a specific published version. When you deploy new code, the LATEST version is updated, but the alias still points to the previous stable version. Traffic continues to flow to the old version until you explicitly update the alias.
The fc-canary plugin automates this process:
Publishes a new version based on the current
LATESTcode and configurations.Updates the alias to split traffic between the previous stable version and the newly published version. If the alias does not already exist, the plugin creates it automatically.
By directing only a specified percentage of invocations to the new version, you can monitor for errors or performance regressions before completing the rollout.
Prerequisites
You have installed Serverless Devs and configured your Alibaba Cloud credentials.
You have deployed a function to Function Compute.
You have installed the
@serverless-cd/fc-canaryplugin in your pipeline configuration.
Parameters
The following table describes the parameters supported by the fc-canary plugin.
| Parameter | Type | Required | Description |
|---|---|---|---|
serviceName | String | Yes (FC 2.0) | The name of the Function Compute 2.0 service that contains the target function. |
functionName | String | Yes (FC 3.0) | The name of the function. Used in Function Compute 3.0, which removes the service-level grouping. |
aliasName | String | Yes | The name of the alias to create or update. For example, prod. |
regionId | String | Yes | The ID of the region where the function is deployed. For example, cn-hangzhou. |
canaryPercent | Number | Yes | The percentage of traffic to route to the new version. Valid values: 0 to 100. |
Usage
Function Compute 2.0
In Function Compute 2.0, aliases are configured at the service level. The following example updates the alias for a service and routes 50% of traffic to the new version:
- plugin: @serverless-cd/fc-canary
inputs:
serviceName: web-framework-kzbp
aliasName: prod
regionId: cn-hangzhou
canaryPercent: 50Function Compute 3.0
In Function Compute 3.0, the service-level grouping is removed. Use the functionName parameter instead of serviceName:
- plugin: @serverless-cd/fc-canary
inputs:
functionName: my-function
aliasName: prod
regionId: cn-hangzhou
canaryPercent: 10Complete the release
After you verify that the new version works as expected, update canaryPercent to 100 or point the alias entirely to the new version to complete the release.