Traffic splitting
Cloud Run functions supports multiple revisions of each function, enabling you to split traffic between different revisions or roll your function back to a prior revision.
Each time you deploy or redeploy a function, a new revision of the underlying Cloud Run service is automatically created. Revisions are immutable and cannot be modified once they are created. To make changes to a function, you must redeploy it.
By default, traffic to a function is routed to its latest revision. You can change this behavior by setting a custom traffic configuration as shown in the next section.
Set a traffic configuration
You can manage how traffic is routed across function revisions through the function's underlying Cloud Run service.
gcloud
To manage traffic using the gcloud CLI:
Deploy your function more than once to create multiple revisions. Be sure to use Cloud Run functions.
Find the revision IDs of the Cloud Run service underlying your function:
gcloud run revisions list --service YOUR_FUNCTION_NAME \ --region YOUR_FUNCTION_REGION \ --format 'value(REVISION)'
The output should be similar to the following:
YOUR_FUNCTION_NAME-00002-xyz YOUR_FUNCTION_NAME-00001-abc
Use the
gcloud run services update-traffic
command with your revision IDs to change the traffic configuration. For example, the following command splits traffic 50/50 between two revisions:gcloud run services update-traffic YOUR_FUNCTION_NAME \ --region YOUR_FUNCTION_REGION \ --to-revisions YOUR_FUNCTION_NAME-00001-abc=50,YOUR_FUNCTION_NAME-00002-xyz=50
Console
To manage traffic using the Google Cloud console:
- Deploy your function more than once to create multiple revisions. Be sure to use Cloud Run functions.
- Go to the Cloud Run functions Overview page in the Google Cloud console.
- Click the name of your function to go to its Function details page.
- In the pane labeled Powered by Cloud Run, click the name of your function to go to the underlying Cloud Run service's Service details page.
- Click the Revisions tab to view the list of revisions.
- In the Revisions tab, click Manage traffic.
- Enter your desired traffic configuration and click Save.
See Rollbacks, gradual rollouts, and traffic migration in the Cloud Run documentation for more details about managing traffic across Cloud Run revisions.