API Gateway集成EB应用(VPC_LINK)报错:ARN需包含路径或操作
问题解决:API Gateway集成VPC_LINK到NLB报错
报错原因
你遇到的BadRequestException: AWS ARN for integration must contain path or action错误,根源在于错误使用了AWS_PROXY集成类型:
AWS_PROXY仅适用于Lambda、Step Functions等AWS原生服务,要求集成URI为符合特定格式的AWS服务ARN(需包含路径/action参数)。- 你的场景是转发HTTP流量到VPC内的NLB,应该使用
HTTP_PROXY类型,而非AWS_PROXY。
修正方案
1. 调整API Gateway集成配置
将aws_api_gateway_integration资源修改为以下内容:
resource "aws_api_gateway_integration" "rest_api_get_destinationId_method_integration" { rest_api_id = aws_api_gateway_rest_api.rest_api.id resource_id = aws_api_gateway_resource.rest_api_destinationId_resource.id http_method = aws_api_gateway_method.rest_api_destination_get_method.http_method integration_http_method = aws_api_gateway_method.rest_api_destination_get_method.http_method # 与API方法保持一致(如GET) type = "HTTP_PROXY" # 替换为HTTP_PROXY类型 uri = "http://${module.nlb.lb_dns_name}/destination/{destinationId}" # 使用NLB的DNS地址+目标路径 connection_type = "VPC_LINK" connection_id = aws_api_gateway_vpc_link.eb_vpc_link.id depends_on = [ aws_api_gateway_resource.rest_api_destinationId_resource, aws_api_gateway_resource.rest_api_destination_resource, aws_api_gateway_method.rest_api_destination_get_method, aws_api_gateway_vpc_link.eb_vpc_link ] }
2. 关键修改点说明
- 集成类型替换:
HTTP_PROXY是专门用于转发HTTP/HTTPS流量到外部服务(包括VPC内的NLB/ALB)的类型,配合VPC_LINK可实现私有子网内服务的访问。 - URI格式修正:不再使用NLB Listener的ARN,改用NLB的DNS名称(通过Terraform模块输出的
lb_dns_name获取),并拼接目标路径/destination/{destinationId},确保流量转发到EB应用的对应端点。 - 移除冗余配置:删除
request_templates,HTTP_PROXY会直接转发请求和响应,无需手动设置statusCode模板(该模板仅适用于AWS_PROXY或自定义集成场景)。
3. 额外检查项
- 确保NLB的安全组允许API Gateway VPC_LINK的流量(API Gateway会在VPC内创建ENI,需允许这些ENI访问NLB的80端口)。
- 确保EB环境的ALB安全组允许NLB的流量访问80端口。
- 确认API Gateway的方法(如GET)与EB应用后端接口的HTTP方法一致。
内容的提问来源于stack exchange,提问作者user2650277
相关产品推荐
相关产品推荐

