Reputation: 1775
I'm trying to migrate from using a Loadbalancer to Cloud API Gateway to reduce costs. My current loadbalancer routes all traffic to two backends, anything starting with /api/
goes to one cloud run backend (a rest API with many endpoints in it), and all other traffic goes to another cloud run backend (service my web bundle). Here's the config:
Do I need to define all my endpoints in the openapi.yaml? I'd rather use a wildcard or prefix notation. I'm hoping to do something like this:
swagger: "2.0"
info:
title: title
description: description
version: "1.0.0"
host: blah.app
schemes:
- "https"
# Specify a backend to handle all routes, paths will be appended to the base path
x-google-backend:
address: https://frontend-cloudrun-backend.a.run.app/
paths:
/api*:
get:
# Per operation overrides
# Path is overwritten and path parameters are specified as query params
x-google-backend:
address: https://api-cloudrun-backend.a.run.app/
/*:
get:
# Per operation overrides
# Path is overwritten and path parameters are specified as query params
x-google-backend:
address: https://frontend-cloudrun-backend.a.run.app/
Upvotes: 0
Views: 1229
Reputation: 336
This should be possible. You can configure the backend service to be addressed both globally and at the operation (path) level. See here.
When specifying the paths in your API Config, you should still keep in mind that the API gateway doesn't support paths with a trailing slashes. For example '/bla/'. Use '/bla' to support '/bla/' and '/bla/*'. See here.
Perhaps one more note: Without the Load Balancer, you can no longer use your own domains. See here.
Upvotes: 1