簡體   English   中英

@aws-cdk/aws-apigatewayv2 中的請求映射和通配符

[英]Request mapping and wildcards in @aws-cdk/aws-apigatewayv2

我正在嘗試在具有以下功能的 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*')中,則會出現錯誤)

對於請求映射的問題,我想獲得以下內容:

從“集成詳細信息”頁面

謝謝!!!

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM