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
相关产品推荐
相关产品推荐

