Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

A URL map can only reference either a backend service or a backend bucket

Hello,

I am reaching out with reference to the following:

https://cloud.google.com/load-balancing/docs/url-map-concepts

It says:

> When you create a URL map, you must specify either a default backend service or a default backend bucket, but not both.

However, in the introduction of the page, it says the following, which gives the impression that the same URL map is referencing both a backend service and a backend bucket:

For example, with an external Application Load Balancer, you can use a single URL map to route requests to different destinations based on the rules configured in the URL map:

  • Requests for any other host and path combination go to a default backend service.

---

Assuming that the URL map is referencing a backend service, shoudln't it say:

Solved Solved
1 10 311
1 ACCEPTED SOLUTION

Yes, a URL map can reference both backend services and backend buckets, but the default backend must be either a service or a bucket—not both.

The example in the docs is correct because path-based routing allows you to direct requests to different destinations. For instance:

  • /video → Backend service
  • /audio → Backend service
  • /images → Cloud Storage backend bucket
  • Other requests → Default backend service

So, while the default backend must be either a service or a bucket, path-based rules let you use both in the same URL map. 😊 

Thanks, 
Darwin Vinoth.
Linkedin 

 



View solution in original post

10 REPLIES 10

Yes, a URL map can reference both backend services and backend buckets, but the default backend must be either a service or a bucket—not both.

The example in the docs is correct because path-based routing allows you to direct requests to different destinations. For instance:

  • /video → Backend service
  • /audio → Backend service
  • /images → Cloud Storage backend bucket
  • Other requests → Default backend service

So, while the default backend must be either a service or a bucket, path-based rules let you use both in the same URL map. 😊 

Thanks, 
Darwin Vinoth.
Linkedin 

 



Hi @DarwinVinoth 

So should i add a patch matcher to my URL map as follows:

gcloud compute url-maps add-path-matcher cross-url-map \

--path-matcher-name=test-path-matcher \ 

--default-backend-bucket=projects/cross-project-backend-bucket/global/backendBuckets/gandalf \

--path-rules=/hello=projects/cross-project-backend-bucket/global/backendServices/cross-ref-backend-service

Seems like the given command is correct! Mostly, it will work. I am not sure about your exact setup. Please try and let me know. 


Thanks, 
Darwin Vinoth.
Linkedin 

 

@DarwinVinoth 

I created the patch matcher, but i can't access the index.html in my backend service.

http://34.8.201.227/hello

I get the following error:

<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</Error>
I can access my bucket though:

http://34.8.201.227/Gandalf.png

 

Can i please seek your guidance.

Please check your cross-ref-backend-service configuration. 

@DarwinVinoth 

My backend service config is as follows:

gcloud compute backend-services create cross-ref-backend-service \

    --load-balancing-scheme=EXTERNAL_MANAGED \

    --protocol=HTTP \

    --port-name=http \

    --health-checks=lb-health-check \

    --global \

    --project=cross-project-backend-bucket

 

Added a backend:

gcloud compute backend-services add-backend cross-ref-backend-service \

    --instance-group=lb-backend \

    --instance-group-zone=us-west1-a \

    --global \

    --project=cross-project-backend-bucket

My instance template is as follows:

gcloud compute instance-templates create backend-template \

    --region=us-west1 \

    --tags=load-balanced-backend \

    --image-family=debian-12 \

    --image-project=debian-cloud \

    --metadata=startup-script='#! /bin/bash

    apt-get update

    apt-get install apache2 -y

    a2ensite default-ssl

    a2enmod ssl

    vm_hostname="$(curl -H "Metadata-Flavor:Google" \

    http://metadata.google.internal/computeMetadata/v1/instance/name)"

    echo "Page served from: $vm_hostname" | \

    tee /var/www/html/hello/index.html

    systemctl restart apache2' \

    --project=cross-project-backend-bucket

 

----

What am i missing here please?

 



It seems like you have created the instance template and backend service. But there is no backend instance or instance group configured for your backend service

Your backend service is created (cross-ref-backend-service), but you haven't added any backend instances or groups to it. 

Thanks, 
Darwin Vinoth.
Linkedin 

 

@DarwinVinoth 

I missed to mention, but i have created an instance group and added a named port to it as well:

Create an instance group:

gcloud compute instance-groups managed create lb-backend \

    --zone=us-west1-a \

    --size=2 \

    --template=backend-template \

    --project=cross-project-backend-bucket

 

Set a named port to the instance group:

gcloud compute instance-groups set-named-ports lb-backend \

    --named-ports=http:80 \

    --zone=us-west1-a \

    --project=cross-project-backend-bucket




Update:

my path  rule had to be `path-rules=/hello/*`

if it is just `/hello`, it throws an error

---------

And thank you @DarwinVinoth . I couldn't have done this without your brilliant insight that there is just one default backend service or backend bucket but with path rules you can redirect traffic to a backend bucket as well.

Thank you. 

Thanks, 
Darwin Vinoth.
Linkedin