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
相关产品推荐
相关产品推荐

