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

使用ApiGatewayV2时Serverless Framework报错:Execution logs不支持http协议

解决ApiGatewayV2 HTTP协议下"Execution logs are not supported on protocolType http"错误

这个错误的根源其实是ApiGatewayV2的HTTP协议(protocolType: HTTP)本身不支持执行日志(Execution Logs)——只有WebSocket协议的ApiGatewayV2才支持这类日志配置。哪怕你把LoggingLevel设为OFF,只要在Stage的路由设置里包含了这类执行日志相关的参数,AWS就会返回这个错误。

你的配置问题所在

你在AWS::ApiGatewayV2::Stage的DefaultRouteSettings里设置了LoggingLevel: OFF和DataTraceEnabled: true,这两个参数都属于执行日志范畴,而HTTP协议的ApiGatewayV2完全不支持这类配置,所以触发了报错。

修正方案

1. 移除执行日志相关的Stage配置

直接删除DefaultRouteSettings里的LoggingLevel和DataTraceEnabled参数,修正后的Stage配置如下:

Stage:
  Type: AWS::ApiGatewayV2::Stage
  Properties:
    ApiId: Ref: Api
    DeploymentId: Ref: Deployment
    StageName: v1
    # 移除了DefaultRouteSettings中与执行日志相关的配置项

2. (可选)配置HTTP协议支持的访问日志(Access Logs)

如果你需要记录API的请求日志,HTTP协议的ApiGatewayV2支持访问日志(Access Logs),可以通过AccessLogSettings配置,示例如下:

Stage:
  Type: AWS::ApiGatewayV2::Stage
  Properties:
    ApiId: Ref: Api
    DeploymentId: Ref: Deployment
    StageName: v1
    AccessLogSettings:
      # 替换成你的CloudWatch日志组ARN
      DestinationArn: arn:aws:logs:us-east-1:123456789012:log-group:my-api-access-logs
      # 自定义日志格式,可根据需求调整
      Format: '{"requestId":"$context.requestId","ip":"$context.identity.sourceIp","httpMethod":"$context.httpMethod","status":"$context.status","responseLength":"$context.responseLength"}'

3. 保留Lambda的日志配置

你对Lambda函数的日志配置是正确的,这个设置不会和API Gateway的错误冲突,可以继续保留:

functions:
  StreamFunction:
    memorySize: 128
    runtime: rust
    handler: hello
    role: StreamRole
    logs:
      executionLogging: false
      fullExecutionData: false

额外注意事项

  • 确认Serverless Framework版本:如果使用较旧版本,可能存在默认添加执行日志配置的情况,建议升级到最新稳定版。
  • 检查无其他隐式配置:确保你的serverless.yml中没有其他插件或全局配置自动添加了执行日志相关的参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 11:28:14