【发布时间】:2020-12-20 01:49:15
【问题描述】:
通过 Lambda 控制台测试 Lambda 本身;我传入“asdf”并得到“ASDF”作为响应。
但是,当我添加 API 网关时:
- 转到 Lambda 控制台:https://us-west-2.console.aws.amazon.com/lambda/home
- 添加触发器
- API 网关
- HTTP API(REST API 有同样的问题)
- 打开
- CORS 已启用
我收到 {"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();
}
}
}
【问题讨论】:
-
这是因为您需要添加 API Gateway 支持。首先,添加
Amazon.Lambda.APIGatewayEvents。然后,更改您的函数签名以接收APIGatewayProxyRequest request, ILambdaContext context并返回APIGatewayProxyResponse。
标签: c# amazon-web-services aws-lambda aws-api-gateway