我是使用Dotnet Core的AWS Lambda的新手。我在Visual Studio上使用AWS Lambda Project(.NET Core)创建了新的项目模板。而且HelloWorld函数非常基本,仅返回UpperCase
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Amazon.Lambda.Core;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace HelloWorld
{
public class Function
{
/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input"></param>
/// <param name="context"></param>
/// <returns></returns>
public string FunctionHandler(string input, ILambdaContext context)
{
return input?.ToUpper();
}
}
}
创建成功并成功发布到AWS。但是我无法在邮递员中调用...我得到以下消息
[
"at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)",
"at Newtonsoft.Json.JsonTextReader.ReadAsString()",
"at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)",
"at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)",
"at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)",
"at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)",
"at Amazon.Lambda.Serialization.Json.JsonSerializer.Deserialize[T](Stream requestStream)",
"at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
]
我在Visual Studio上使用AWSToolkitPackage运行测试,它可以正常工作!因为输入参数是一个字符串。但是在PostMan上,我也尝试放置一个字符串,但是它不起作用...有人对此有经验吗?非常感谢。
答案 0 :(得分:1)
您缺少此行
using Amazon.Lambda.Serialization;
没有该行,此行
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
不是真的有效
答案 1 :(得分:0)
啊!!!我找到了解决方案。代替使用“字符串”,而使用“ JObject”代替