AWS Lambda (.NET) + SQS:将 Lambda 事件 JSON 负载转换为字符串时出错
AWS Lambda (.NET) + SQS: Error converting the Lambda event JSON payload to a string
我使用 AWS Lambda(.NET Core 2.1 环境)+ SQS 作为触发器
问题是我的 lambda 无法解析我的 SQS 消息。
Error converting the Lambda event JSON payload to a string. JSON
strings must be quoted, for example "Hello World" in order to be
converted to a string: Unexpected character encountered while parsing
value: {. Path '', line 1, position 1.: JsonSerializerException
这是我的处理程序的声明:
public async Task<string> FunctionHandler(DummyMessage message, ILambdaContext context)
型号:
public class DummyMessage {
public string Label { get; set; }
}
我尝试从 AWS 控制台输入 SQS:{"Label":"qwerty"}
、"{"Label":"qwerty"}"
、"{\"Label\":\"qwerty\"}"
,但出现相同的错误。
你能帮忙解决这个问题吗?
当通过 Json 时尝试从 Newtonsoft.Json.Linq
中获取 JObject
FunctionHandler(JObject eventStr, ILambdaContext context)
然后您可以反序列化从 Amazon.Lambda.SQSEvents SDK 库继承 SQSEvent 的响应。
var result = eventStr.ToObject<SQSEvent>();
此外,不要忘记 add/change aws serializer :
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace AwsLambdaHandleTelegramWebhooks
{
public class Function
{
public APIGatewayProxyResponse FunctionHandler(JObject input,ILambdaContext context)
{
我使用 AWS Lambda(.NET Core 2.1 环境)+ SQS 作为触发器
问题是我的 lambda 无法解析我的 SQS 消息。
Error converting the Lambda event JSON payload to a string. JSON strings must be quoted, for example "Hello World" in order to be converted to a string: Unexpected character encountered while parsing value: {. Path '', line 1, position 1.: JsonSerializerException
这是我的处理程序的声明:
public async Task<string> FunctionHandler(DummyMessage message, ILambdaContext context)
型号:
public class DummyMessage {
public string Label { get; set; }
}
我尝试从 AWS 控制台输入 SQS:{"Label":"qwerty"}
、"{"Label":"qwerty"}"
、"{\"Label\":\"qwerty\"}"
,但出现相同的错误。
你能帮忙解决这个问题吗?
当通过 Json 时尝试从 Newtonsoft.Json.Linq
中获取 JObjectFunctionHandler(JObject eventStr, ILambdaContext context)
然后您可以反序列化从 Amazon.Lambda.SQSEvents SDK 库继承 SQSEvent 的响应。
var result = eventStr.ToObject<SQSEvent>();
此外,不要忘记 add/change aws serializer :
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace AwsLambdaHandleTelegramWebhooks
{
public class Function
{
public APIGatewayProxyResponse FunctionHandler(JObject input,ILambdaContext context)
{