Host AWS and GCP functions under the same domain cached by Cloudflare

Pedro Gomes
2 min readJul 24, 2021

--

At my current project we’re currently running on AWS and GCP, one of the reasons being we’re using BigQuery for BI Analytics together with the parent company.

[todo]

Setup an API Gateway, this will proxy all requests to GCP:

Setup a “Custom Domain Name” in AWS API Gateway console, with the API mappings required for both your GCP functions and your AWS functions:

Create a DNS record pointing to the hostname mentioned in “Custom Domain Name” above:

Ensure you have a Cloudflare “Page Rule” with the settings seen below to ensure the API responses will be cached by Cloudflare.

Ensure your application is returning the proper caching headers:

curl -I "https://prod.service-api.com/service2/function2" -s | grep -I cache
cache-control: max-age=30, stale-while-revalidate=90
cf-cache-status: HIT

Profit! You know have both AWS and GCP API’s available from the same subdomain and being cached near the user at Cloudflare PoPs.

--

--

No responses yet