How to map Google Domains domain name to Google Cloud Run project ? I can't make 'www' work

I've purchased a Google Domains domain name and try to map my Cloud Run project to it.

To do so, in my Google Domain account, I added in the "DNS Settings" page, under custom resource records, two records:

  1. @ A 1h xxx.xxx.xx.xx (ip that I got from the Custom domain mappings -> DNS records in the Cloud run page)
  2. www CNAME 1h example.com.

From what I've read here: https://support.google.com/domains/answer/3251147?authuser=1#zippy=%2Ccname , this should be enough so that my urls "https://example.com" and "https://www.example.com" work but that's not the case. Only "https://example.com" works, and the one with "www" gives me a Google 404 page.

Any idea how I could make the "www" work ?

Thanks!


Finally managed to make it work:

  1. Made two custom mappings in Cloud Run (one for the example.com and one for the www.example.com).
  2. In Google Domains, I added 3 custom resources records:

@ A 1h xxx.xxx.xx.xx

@ TXT 1h "verification_key" # I had to add this record to verify my www.example.com domain

* A 1h xxx.xxx.xx.xx

I think the key to make it work was to map the wildcard to the DNS A ip.


As mentioned in the comment by @JohnHanley the correct way is to add one mapping for each subdomain (www is a subdomain also) and then proceed to update your DNS with each entrance. To do so you can follow the next steps:

Map a custom domain to a service

  1. Open the domain mappings page in the Google Cloud Console: Domain mappings page

  2. In the Domain Mappings page, click Add Mapping.

  3. From the dropdown list in the Add Mapping form, select the service you are mapping the custom domain to:

  4. Enter the domain name.

  5. Click Continue.

  6. You need to verify the ownership of a domain before being able to use it, unless you purchased your domain from Google. If you want to map subdomain.example.com, you should verify ownership of example.com. For more information on verifying domain ownership, refer to Webmaster Central help

Add your DNS records at your domain registrar

After you've mapped your service to a custom domain in Cloud Run, you need to update your DNS records at your domain registrar. Cloud Run generates and displays the DNS records you need to enter, you can retrieve the records for each entry here. You must add these records that point to the Cloud Run service at your domain registrar for the mapping to go into effect. I want to emphasize the next part on the documentation as it mentions the www subdomain:

When you add each of the above DNS records to the account at the DNS provider:

  1. Select the type returned in the DNS record in the previous step: A, or AAAA, or CNAME.
  2. Use the name www to map to www.example.com

And that's the right way to perform the domain mapping for the www subdomain