Skip to main content

Traffic Routing

Use traffic routing commands to configure and view traffic distribution across cloud function versions, enabling gradual release and version rollback.

Configure Version Traffic​

Use the tcb fn config-route command to configure traffic distribution for function versions:

tcb fn config-route <functionName> <version1> <traffic1> [version2] [traffic2]

Parameter Description:

ParameterDescriptionRequired
functionNameFunction nameYes
version1First version number, can be a specific version or $LATESTYes
traffic1Traffic percentage for the first version, an integer from 0 to 100Yes
version2Second version numberNo
traffic2Traffic percentage for the second version, an integer from 0 to 100No

Usage Examples:

# Allocate 10% traffic to version 2, remaining 90% to $LATEST
tcb fn config-route app 2 10

# Allocate 30% traffic to version 1, 70% to version 2
tcb fn config-route app 1 30 2 70

# Switch 100% traffic to version 3
tcb fn config-route app 3 100

Parameter Validation:

  • traffic1 / traffic2 must be an integer from 0 to 100
  • version2 and traffic2 must be specified together
  • version1 and version2 cannot be the same version
  • When two versions are specified, traffic1 and traffic2 must sum to 100
  • When version2 is omitted and version1 is $LATEST, traffic1 must be 100

View Traffic Configuration​

Use the tcb fn get-route command to view traffic configuration for function versions:

tcb fn get-route <functionName>

The command displays the configuration according to the current traffic policy type:

  • Ratio-based (FLOW): displays the traffic ratio of each version
  • Header matching (HEADERS): displays the request header matched by each version (Key = Value)
  • Legacy configuration: reports that it cannot be displayed and suggests using --json to view the raw data

Usage Example:

# View traffic configuration for app function
tcb fn get-route app

# View the raw traffic configuration as JSON
tcb fn get-route app --json

Important Notes​

  • When only one version is specified, the remaining traffic is allocated to the $LATEST version
  • Traffic routing configuration takes effect immediately, adjustments will impact live traffic instantly
  • It is recommended to perform traffic adjustments during off-peak business hours