【发布时间】:2018-06-21 12:42:40
【问题描述】:
我是使用 Dotnet Core 的 AWS Lambda 新手。我在 Visual Studio 上使用 AWS Lambda Project (.NET Core) 创建了新的项目模板。 HelloWorld 函数非常基本,只返回大写字母
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。但我无法在 Postman 中调用...我收到以下消息
[
"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 上,我也尝试放置一个字符串,但它没有用......有没有人有这方面的经验?非常感谢。
【问题讨论】:
-
你能在你的 lambda 中发布你所有的代码吗?
-
你好,我更新了完整的代码。谢谢