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

AWS Lambda测试事件报错:JSON数据意外结束的排查求助

AWS Lambda C# 反序列化成功但返回JSON解析错误问题

测试AWS Lambda时遇到异常:发送的JSON输入能被正确反序列化,Lambda业务逻辑也按预期执行,但AWS平台测试时返回错误:

Calling the invoke API action failed with this message: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

本地通过AWS测试工具运行无此问题。

相关代码与配置

输入JSON

{
  "DeliveryPartnerName": "XXXXX",
  "ParentDeliveryPartnerId": 42,
  "BatchSize": 42,
  "SendEmails": true,
  "SendSMS": true,
  "VolumePerBatch": 10
}

C# 模型类

public class ExecutionRequest
{
    public int BatchSize { get; set; }
    public string DeliveryPartnerName { get; set; }
    public int ParentDeliveryPartnerId { get; set; }
    public bool? SendEmails { get; set; }
    public bool? SendSMS { get; set; }
    public int? VolumePerBatch { get; set; }
}

Lambda 序列化配置

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

FunctionHandler 代码片段

public class Function
{
    public async Task FunctionHandler(ExecutionRequest input, ILambdaContext context)
    {
        var host = Host.CreateDefaultBuilder()
            .ConfigureAppConfiguration((hostingContext, config) => ...

依赖注册

services.AddSingleton(input)

模型使用示例

var orders = await orderRepository.GetOrders(request.DeliveryPartnerName);

使用的NuGet包版本

  • AWSSDK.Core 3.7.12.11
  • AWSSDK.Lambda 3.7.13.25
  • Amazon.Lambda.Core 2.1
  • Amazon.Lambda.Serialization.Json 2.1.0

核心疑问:JSON已正确反序列化,Lambda逻辑正常运行,但AWS返回上述JSON解析错误,请问该如何排查解决?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 22:06:23