If you're hosting your website on Google Cloud Run, you might want to use your own domain name instead of the default URL Google gives you. It's not hard to set up, and it makes your site look more professional. In this post, I'll walk you through how to add a custom domain to your Cloud Run service, keeping it simple and cheap.
Prerequisite: I'm assuming you've already set up your Cloud Run service in a Google Cloud Platform project. If you haven't, check out my earlier article on setting up Cloud Run.
Before Google lets you use your domain with Cloud Run, you need to prove you own it. This happens through Google Search Console. Here's what to do:
Note: You'll need access to your registrar's DNS management page. If you're stuck, their help docs should point you in the right direction.
For more details, see the official Google Cloud Run custom domains documentation.
Once your domain is verified, you can connect it to Cloud Run. Here's how:
What's this A and AAAA stuff? A records connect your domain to IPv4 addresses, and AAAA records do the same for IPv6. Cloud Run uses multiple addresses for reliability, so you get four of each.
Tip: After adding the records, you can check if they're working with a tool like "dig" or an online DNS checker.
Want your site to work with www.yourdomain.com
too? It's an extra step, but easy.
www.yourdomain.com
.What's a CNAME? It's like a shortcut - it points www.yourdomain.com
to your main Cloud Run address. For more info on other DNS records, check out Cloudflare's DNS Records article.
After setting up the DNS records, Google handles the security part by creating an SSL/TLS certificate. This makes your site use HTTPS, which is a must these days. It takes about 30 minutes, though sometimes a bit longer. You'll see the status update in Cloud Run when it's done. While it's processing, your site might not load, or you might see browser warnings. That's normal - just wait it out.
Here is how your mappings will appear after you have correctly followed the steps above:
Before you go all-in on this method, there are a few limitations to keep in mind:
/
), not a specific path like /blog
. Wildcard domains (*.yourdomain.com
) are also not supported with this method.us-central1
, us-east1
, europe-west1
, and asia-northeast1
. If your service is hosted elsewhere, you must use a different mapping option.Here's the breakdown:
Domain: About $10-15 per year, depending on your registrar and domain type.
Cloud Run: There's a free tier that covers a decent amount of usage. After that, you pay only for what you use-requests, CPU, and memory. For small sites, it's often pennies a month.
The domain mapping itself? Free. No hidden fees there.
How long does DNS propagation take? DNS propagation can take up to 48 hours, but it's usually much faster—often within a few hours. If your site isn't working right away, give it some time and check your DNS records for typos.
Is Cloud Run suitable for static sites? Yes. While Cloud Run is often used for dynamic backends, it can also serve static frontends like React or Vue. You can learn how to do this in my guide on serving a React frontend with FastAPI.
Can I use a subdomain with Cloud Run?
Absolutely. You can map subdomains (like blog.yourdomain.com
) to your Cloud Run service by adding the appropriate DNS records and domain mappings in the Cloud Run console.
What if HTTPS doesn't work after setup? SSL/TLS provisioning can take up to 30 minutes or more. If HTTPS isn't working after that, check your DNS records for errors and review Cloud Run's documentation for troubleshooting tips.
Do I need to pay extra for domain mapping on Cloud Run? No, domain mapping itself is free. You only pay for your domain registration and any Cloud Run usage beyond the free tier.
Can I use www and non-www versions of my domain?
Yes, you can map both www.yourdomain.com
and yourdomain.com
to your Cloud Run service. Just follow the steps for adding a www subdomain mapping.
That's it! Once everything's set, your website will run on your custom domain with HTTPS, all hosted on Cloud Run. It's a cheap way to get a professional setup - just the cost of your domain and whatever Cloud Run usage you rack up beyond the free tier.
Want to learn more about deploying FastAPI apps to Cloud Run? Read my step-by-step guide here. Once your app is live, you might also want to look into advanced performance tuning.
David Muraya is a Solutions Architect specializing in Python, FastAPI, and Cloud Infrastructure. He is passionate about building scalable, production-ready applications and sharing his knowledge with the developer community. You can connect with him on LinkedIn.
Enjoyed this blog post? Check out these related posts!
Advanced Performance Tuning for FastAPI on Google Cloud Run
From Cold Starts to Concurrency: A Deep Dive into FastAPI Performance on Cloud Run.
Read More..
Connecting FastAPI to a Database with SQLModel
A practical guide to building CRUD APIs with FastAPI and SQLModel.
Read More..
Running Database Migrations with Alembic in Google Cloud Build
How to Organize and Load FastAPI Settings from a .env File Using Pydantic v2
Read More..
Have a project in mind? Send me an email at hello@davidmuraya.com and let's bring your ideas to life. I am always available for exciting discussions.