6

I am currently building a rest api, for this I am using Google Cloud API Gateway and Google Cloud Run. I've been looking at all the google cloud documentation and researching elsewhere and I can't find how to add a custom domain to an API gateway instance. The funny thing is that there is more documentation for Google Cloud endpoints, I could find how to do it with endpoints but it does not apply to my use case.

I have 10 instances of google cloud run each one running a microservice respectively and I want to join everything in a single domain and add support with openapi, but I have failed in the attempt.

In any case, if someone has managed to customize the domain of an api gateway instance, I would appreciate if you could guide me, greetings.

andrefedev
  • 157
  • 2
  • 10
  • Have you had any CORS errors? I am getting this error: "Access to fetch at curl https://my-gateway-a12bcd345e67f89g0h.uc.gateway.dev/hello?key=example' from origin 'https://example.netlify.app' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled." Maybe both of our experiences stem from a lack of customization? – ElektrikSpark Oct 09 '20 at 13:38
  • @ElektrikSpark Maybe this has to do with netlify, but this would be a problem for another question. Returning apparently for now it is not possible to enable a custom domain for the gateway api. – andrefedev Oct 09 '20 at 15:36
  • I am thinking that there may be a need to set up CORS headers in the OpenApi config. Is this something that you have explored? Anyway, it is my understanding that there is currently no way to customize the domain name, maybe this will be an option when the service leaves beta. – ElektrikSpark Oct 09 '20 at 15:42

2 Answers2

4

For the beta release, custom domain names are not supported on GCP for API Gateway. Since it is still beta as of today, if you want to use a custom domain, you could use Cloud Endpoints in Cloud Run or you could even look into using Microservices in App Engine.

David
  • 646
  • 4
  • 14
0

It is now possible to use custom domain with API Gateway. Feature is available in pre-GA as of May 2023.

You can set custom audiences on a service using the following command:

gcloud beta run services update SERVICE --add-custom-audiences=AUDIENCE

Replace

SERVICE with the name of your Cloud Run service

AUDIENCE with a string for the custom audience you want to support, for example example.com

Verifying custom audiences:

export TOKEN=$(gcloud auth print-identity-token --impersonate-service-account SERVICE_ACCOUNT_EMAIL --audiences='AUDIENCE')

Please find it here: https://cloud.google.com/run/docs/configuring/custom-audiences

It was made available in response to this issue: https://issuetracker.google.com/issues/181220765