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

798 views Asked by At

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:

From the "integration details" page

Thanks!!!

1

There are 1 answers

0
Zweer On

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