简体   繁体   中英

Request mapping and wildcards in @aws-cdk/aws-apigatewayv2

I'm trying to add a HttpRoute in a HttpApi with the following features:

  • a wildcard after the initial path: i'd like to proxy everything after "/foo" (such as "/foo", "/foo/bar" etc) to an ecs service (via HttpServiceDiscoveryIntegration, already set)
  • a request mapping so that the path is correctly handled (I'm using stages for the Api)

Right now I've the following code:

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

I can't find the right place to put the wildcard (if I put the wildcard inside the HttpRouteKey.with('/foo*') it rises an error)

For what concerns the request mapping, I'd like to obtain what follows:

从“集成详细信息”页面

Thanks!!!

Found out CDK doesn't support what I wanted, so I used the Cfn classes:

    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}`,
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM