You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS CDK:如何获取HTTP API Gateway的Integration ID并关联路由

解决AWS CDK(C#)中获取HTTP API Gateway集成ID并关联路由的问题

在使用AWS CDK(C#)创建HTTP API Gateway集成后,无需手动查找集成ID,直接通过CfnIntegration的内置属性即可获取,修改代码如下:

创建集成并获取ID

var cfnIntegration = new CfnIntegration(this, "Integration", new CfnIntegrationProps()
{
   ApiId = cfnAPI.AttrApiId,
   IntegrationType = "AWS_PROXY",
   IntegrationUri = "arn:aws:lambda:us-east-1:123456789:function:TestFunction",
   IntegrationMethod = "POST",
   PayloadFormatVersion = "2.0",
});

// 集成ID可通过 cfnIntegration.AttrIntegrationId 直接引用

关联集成到路由

CfnRoute cfnRoute = new CfnRoute(this, "Routes", new CfnRouteProps()
{
  ApiId = cfnAPI.AttrApiId,
  RouteKey = "POST /webhook/digitalChannel",
  Target = $"integrations/{cfnIntegration.AttrIntegrationId}"
});

AttrIntegrationId是AWS CDK为CfnIntegration资源提供的属性,部署阶段会自动解析为实际的集成ID,确保路由与集成正确关联。

内容的提问来源于stack exchange,提问作者Aniruddha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 02:50:23