I use AWS ECS for my server (multiple microservers) in some website, and I use API Gateway + OpenApi to define the routes and to integrate them with the ECS microservers.
Every path prefix should integrate with different ECS and direct all subpaths to there.
Is there a way to use some regex in OpenApi to integrate it with ALL paths and operations under some path?
This is how I'm defining the path for single path and single operation:
OpenApi:
openapi: "3.0.1"
info:
title:
Fn::Sub: "${EnvironmentName}-api"
version: 0.0.1
paths:
/api/project:
get:
responses:
default:
description: "Default response for GET"
x-amazon-apigateway-integration:
payloadFormatVersion: "1.0"
connectionId:
Fn::ImportValue:
Fn::Sub: ${EnvironmentName}:HttpApiVPCLink
type: "http_proxy"
httpMethod: "ANY"
uri:
Fn::ImportValue:
Fn::Sub: ${EnvironmentName}:DiscoveryService-microserver-1
connectionType: "VPC_LINK"
/api/item:
get:
responses:
default:
description: "Default response for GET"
x-amazon-apigateway-integration:
payloadFormatVersion: "1.0"
connectionId:
Fn::ImportValue:
Fn::Sub: ${EnvironmentName}:HttpApiVPCLink
type: "http_proxy"
httpMethod: "ANY"
uri:
Fn::ImportValue:
Fn::Sub: ${EnvironmentName}:DiscoveryService-microserver-2
connectionType: "VPC_LINK"
So in this code:
/api/project
with operation get will use microserver1 and/api/item
with operation get will use microserver2But what I need is every route with prefix /api/project
and any operation will use microserver1,
for example - post operation or route /api/project/{id}
should also use the microserver1 without additional definition in the OpenApi file
Is there any way to define something like that?
Use the proxy integration. See Documentations
When you use the proxy integration, your all sub API will be proxied to the targets.