![](/img/trans.png)
[英]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.