Serverless Cloud Function (SCF) allows you to configure traffic routing. With this feature, you can easily control the beta launch or rollback process in actual use cases or environments in order to avoid the risks that may be brought by direct launch.
When creating an alias or adjusting the traffic configuration, you can point the traffic to two function versions in the console, so that the traffic can be routed between versions by the specified rule. Currently, two routing schemes are supported, namely, random routing by weight and routing by rule.
This document uses configuration during alias creation as an example to describe how to configure routing. After the alias is created, traffic will be randomly routed to two versions by the specified percentages. The steps are as follows:
The current rule syntax for routing by rule consists of the following three parts:
invoke.headers.[userKey]
where [userKey]
can be modified. This format indicates that when the invoke
API is called, the userKey
part in headers
of the HTTP request will be used for match.exact
and range
match methods are supported.exact
: exact match. When the exact
method is used, the match expression should be a string. If the value read through the match key is exactly the same as the expression, the rule will be hit.range
: range match. When the range
method is used, the match expression should be in the format of (a,b)
or [a,b]
where a
and b
need to be integers. If the value read through the match key is an integer in the range specified by the expression, the rule will be hit.You can configure routing by rule in the following steps:
invoke.headers.User exact Bob
and set that of version 1 to "miss", you can set the fields as shown below:invoke
API, if the routingKey
parameter is set to {"User":"Bob"}
, version 2's code and configuration will be used during this execution; if the routingKey
parameter is not set or set to another value, version 1's code and configuration will be used.invoke.headers.userHash range [1,50]
and set that of version 2 to "miss", you can set the fields as shown below:invoke
API, if the routingKey
parameter is set to {"userHash":30}
, version 3's code and configuration will be used during this execution; if the routingKey
parameter is not set or set to another value such as {"userHash":80}
, version 2's code and configuration will be used.
Was this page helpful?