0

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!

kaycee401
  • 19
  • 1
  • 2
  • Would adding 2 custom domains for your Cloud Run service like [this](https://stackoverflow.com/questions/60189101/google-cloud-run-not-supporting-domain-and-subdomain-at-same-time/60194288#60194288) work or do you get an error message when you try to do this ? – Frank Feb 10 '21 at 22:44
  • I just tried to add a second custom domain pointing to www.example.com. I needed to verify it by adding a TXT record in Google Domains, which succeeded, but my new custom domain in Cloud Run only gives me A and AAAA records, and no CNAME record, so the CNAME mapping of "www" in Google Domains still don't work. – kaycee401 Feb 11 '21 at 14:00

3 Answers3

1

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.

kaycee401
  • 19
  • 1
  • 2
  • The Google Front End (GFE) only recognizes domain names that are preconfigured by Custom Domains. Everything else will receive a 404 except for the service URL. Do not use a wildcard resource record type. – John Hanley Feb 14 '21 at 00:02
  • Thanks for your comment @JohnHanley. What would you suggest ? – kaycee401 Feb 16 '21 at 17:34
  • 2
    In regards to what? My advice is to not use wildcard records. This means using resource records with names and not a wildcard. For each dns name (example.com, www), you will need to create a Cloud Run custom domain and setup the matching DNS resource records. – John Hanley Feb 16 '21 at 19:31
1

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

daraeman
  • 3
  • 3
Emmanuel
  • 131
  • 3
0

Map the base domain example.com and setup the DNS records, then map another like below and Google spits out a different DNS configuration that uses a CNAME record.

*[master][~]$ gcloud beta run domain-mappings create --service=my-service --domain www.example.com
Creating......done.                                                                                                                                                                                                                      
Waiting for certificate provisioning. You must configure your DNS records for certificate issuance to begin.
NAME  RECORD TYPE  CONTENTS
www   CNAME        ghs.googlehosted.com.

I'm still waiting for DNS cache expiry to check it all through but if I don't post this now, I never will.

Luke Puplett
  • 939
  • 2
  • 16
  • 24