Host AWS and GCP functions under the same domain cached by Cloudflare
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.
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
Profit! You know have both AWS and GCP API’s available from the same subdomain and being cached near the user at Cloudflare PoPs.