0

我正在尝试在具有以下功能的 HttpApi 中添加 HttpRoute:

  • 初始路径后的通配符:我想将“/foo”之后的所有内容(例如“/foo”、“/foo/bar”等)代理到 ecs 服务(通过 HttpServiceDiscoveryIntegration,已设置)
  • 请求映射,以便正确处理路径(我正在为 Api 使用阶段)

现在我有以下代码:

new HttpRoute(scope, 'Route', {
  httpApi,
  routeKey: HttpRouteKey.with('/foo'),
  integration: new HttpServiceDiscoveryIntegration({
    service: service.cloudMapService!,
    vpcLink: VpcLink.fromVpcLinkAttributes(scope, 'VpcLink', {
      vpc,
      vpcLinkId: 'aaa',
    }),
  }),
});

我找不到放置通配符的正确位置(如果我将通配符放在里面HttpRouteKey.with('/foo*')会出现错误)

对于请求映射的问题,我想获得以下内容:

来自

谢谢!!!

4

1 回答 1

1

发现 CDK 不支持我想要的,所以我使用了 Cfn 类:

    const integration = new CfnIntegration(scope, 'Integration', {
      apiId: httpApi.apiId,
      integrationType: HttpIntegrationType.HTTP_PROXY,
      integrationUri: service.cloudMapService!.serviceArn,
      integrationMethod: HttpMethod.ANY,
      connectionId: vpcLink.vpcLinkId,
      connectionType: HttpConnectionType.VPC_LINK,
      payloadFormatVersion: PayloadFormatVersion.VERSION_1_0.version,
      requestParameters: {
        'overwrite:path': '$request.path',
      },
    });

    new CfnRoute(scope, 'BeckyRoute', {
      apiId: httpApi.apiId,
      routeKey: `ANY /foo`,
      target: `integrations/${integration.ref}`,
    });

    new CfnRoute(scope, 'BeckyProxyRoute', {
      apiId: httpApi.apiId,
      routeKey: `ANY /foo/{proxy+}`,
      target: `integrations/${integration.ref}`,
    });
于 2021-05-27T17:04:19.580 回答