Stay organized with collections Save and categorize content based on your preferences.

Traffic splitting

Cloud Functions (2nd gen) 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:

  1. Deploy your function more than once to create multiple revisions. Be sure to use Cloud Functions (2nd gen).

  2. 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
    
  3. 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:

  1. Deploy your function more than once to create multiple revisions. Be sure to use Cloud Functions (2nd gen).
  2. Go to the Cloud Functions Overview page in the Google Cloud console.
  3. Click the name of your function to go to its Function details page.
  4. 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.
  5. Click the Revisions tab to view the list of revisions.
  6. In the Revisions tab, click Manage traffic.
  7. 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.