App Engine custom domain with service
Asked Answered
S

3

26

I set up a custom domain with App Engine after following the instructions on DNS records:

https://cloud.google.com/appengine/docs/standard/java/mapping-custom-domains

It's working for the default service using URL http://MY_CUSTOM_DOMAIN but I'm unable to access other services with URLs http://SERVICE_ID.MY_CUSTOM_DOMAIN. Do I need to map a different set of DNS records?

Sandon answered 25/3, 2018 at 21:8 Comment(0)
P
19

Check how to use subdomains and how wildcard mapping works in the GCP docs here (actually these are the next steps at the website which you've followed and linked). Make sure that your DNS provider permits wildcards in CNAME host entries, otherwise such mapping will not be possible.

This blog post shows a real-life example of matching subdomains to services with App Engine.

Patinated answered 25/3, 2018 at 21:56 Comment(2)
Key take away, if your service is named "api" and you create a custom domain for "api.expample.com", App Engine will automatically match it.Moultrie
@Moultrie In my case I found only http works, if you need TLS connection, dispatch.yaml seems the only way.Invigilate
P
28

Here's a step-by-step:

  1. Ensure you are a owner of the parent domain in here: https://www.google.com/webmasters/verification/home (e.g for subdomain.example.com you need to own example.com) If not, ask a friend to add you as an owner.
  2. Create a CNAME record pointing to: ghs.googlehosted.com (in Cloud DNS or wherever). Note: This will cause downtime, but it is required for App Engine to create an SSL certificate so downtime is unavoidable...
  3. Add custom domain to App Engine
    1. Go to App Engine -> Settings -> Custom Domains
    2. Click on Add a custom domain
    3. Choose the verified parent domain and click Continue
    4. Enter the subdomain (e.g subdomain.example.com) and click Save mappings
    5. Click Done (you already did this last step)
  4. Update App Engine dispatch rules
    1. Run gcloud app describe --project <GOOGLE_CLOUD_PROJECT_ID> and take a look at the current section of dispatchRules
    2. Create dispatch.yaml or dispatch.yml file with your new rule as well as the ones already existing above (note the file format is different from the command output)
    dispatch:
      - url: <DOMAIN>/* # e.g. subdomain.example.com/*
        service: <SERVICE-NAME>
    
    1. Deploy it using: gcloud app deploy dispatch.yaml --project <GOOGLE_CLOUD_PROJECT_ID>
Prissy answered 16/6, 2019 at 14:9 Comment(3)
@henry-woody both dispatch.yaml and dispatch.yml workPrissy
Is it possible to do sub-domain only? Which is a very common use case?Wooldridge
I am looking for an approach not using dispatch.yaml, per cloud.google.com/appengine/docs/legacy/standard/python/…Invigilate
P
19

Check how to use subdomains and how wildcard mapping works in the GCP docs here (actually these are the next steps at the website which you've followed and linked). Make sure that your DNS provider permits wildcards in CNAME host entries, otherwise such mapping will not be possible.

This blog post shows a real-life example of matching subdomains to services with App Engine.

Patinated answered 25/3, 2018 at 21:56 Comment(2)
Key take away, if your service is named "api" and you create a custom domain for "api.expample.com", App Engine will automatically match it.Moultrie
@Moultrie In my case I found only http works, if you need TLS connection, dispatch.yaml seems the only way.Invigilate
A
0

For anyone who encounters the issue with mapping the new domain and not seeing it in the list of mapped domains, try to add the mapping from CLI like so:

gcloud app domain-mappings create xxxxx.yourdomain.com --project=your-project

additionally, make sure you setup the DNS properly. e.g.:

A record: @ -> 216.239.32.21
A record: @ -> 216.239.34.21
A record: @ -> 216.239.36.21
A record: @ -> 216.239.38.21 
Apricot answered 30/5 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.