[英]Internal Server Error returned when accessing aws Serverless API deployed to AWS API gateway
[英]Deploying to AWS Lambda in VS2019 with API Gateway gives {“message”:“Internal Server Error”}
通过 Lambda 控制台测试 Lambda 本身; 我传入“asdf”并得到“ASDF”作为响应。
但是,当我添加 API 网关时:
我收到一条 {"message":"Internal Server Error"}
此代码有效(删除input
参数):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Amazon.Lambda.Core;
using Complyify.Contexts;
using Complyify.Engines;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace ComplyifyLambda
{
public class Function
{
public string FunctionHandler(/* string input, */ ILambdaContext context)
{
return "Hello, World";
}
}
}
此代码不起作用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Amazon.Lambda.Core;
using Complyify.Contexts;
using Complyify.Engines;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace ComplyifyLambda
{
public class Function
{
public string FunctionHandler(string input, ILambdaContext context)
{
return input?.ToUpper();
}
}
}
正如@zaitsman 指出的,我需要使用Amazon.Lambda.APIGatewayEvents
NuGet 包。
我发现这个答案很有用。
此代码有效:
public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
var bodyString = request?.Body;
if (!string.IsNullOrEmpty(bodyString))
{
return new APIGatewayProxyResponse
{
StatusCode = 200,
Body = bodyString.ToUpper()
};
}
return new APIGatewayProxyResponse
{
StatusCode = 200,
Body = "No body!"
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.