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

AWS Lambda配置SQS批量失败项上报后返回值报错求助

问题排查:Lambda返回"handler returns a single value, but it does not implement error"错误

报错原因

Go语言的Lambda运行时对handler的返回值有明确规则:

  • 若handler仅返回单个值,该值必须实现error接口
  • 当需要返回自定义响应结构体(如SQS批量失败响应)时,必须返回两个值:第一个是响应对象,第二个是error类型(无错误时返回nil)

你的当前handler仅返回SQSBatchResponse一个值,不符合Lambda Go运行时的返回规范,因此触发该错误。

修复后的代码

修改handler的返回值定义,添加error返回值:

type SQSBatchResponse struct {
    BatchItemFailures []SQSMessage 
}

type SQSMessage struct {
    MessageId string
}

func Handler(_ context.Context, sqsEvent events.SQSEvent) (sqsResponse SQSBatchResponse, err error) {
    // 你的业务逻辑代码
    
    return sqsResponse, nil
}

验证说明

修改后,Lambda运行时会正确识别批量失败响应结构体,第二个返回值nil表示处理过程无错误,完全符合SQS批量消息处理的失败报告要求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 17:12:12