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

如何通过CLI在AWS API Gateway中为路由绑定对应集成?

这个操作完全可以通过aws cli完成,不需要依赖网页控制台。你没有找到对应命令是因为路由和集成的绑定逻辑被集成在update-route接口中,没有单独的绑定命令。

你在创建完集成后,会拿到返回的IntegrationId,调用update-route时通过--target参数指定integrations/{你的集成ID}即可完成绑定。

如果要适配容器启动的自动化脚本,可以参考下面的全流程可执行命令,不需要手动复制粘贴ID:

# 1. 创建API并保存API_ID
API_ID=$(awslocal apigatewayv2 create-api --name="test-api" --protocol="http" --query 'ApiId' --output text)

# 2. 创建集合并保存INTEGRATION_ID
INTEGRATION_ID=$(awslocal apigatewayv2 create-integration \
  --api-id $API_ID \
  --integration-type AWS \
  --integration-uri arn:aws:lambda:us-east-1:000000000000:function:some-lambda \
  --query 'IntegrationId' --output text)

# 3. 创建路由
ROUTE_ID=$(awslocal apigatewayv2 create-route \
  --api-id $API_ID \
  --route-key '$default' \
  --query 'RouteId' --output text)

# 4. 绑定路由和集成(核心操作)
awslocal apigatewayv2 update-route \
  --api-id $API_ID \
  --route-id $ROUTE_ID \
  --target "integrations/$INTEGRATION_ID"

补充说明:

  • 除了$default路由外,所有自定义路由的绑定逻辑都和上面一致,只需要替换对应的route-id和integration-id即可
  • 如果绑定后调用接口出现权限错误,可额外通过cli命令给Lambda添加API Gateway的调用权限,完全符合全CLI配置的要求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 21:54:08