Reputation: 15399
Testing the Lambda itself works from the Lambda console; I pass in "asdf" and get "ASDF" as a response.
However when I add an API Gateway:
I get a {"message":"Internal Server Error"}
This code works (removing the input
parameter):
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";
}
}
}
This code does not work:
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();
}
}
}
Upvotes: 0
Views: 349
Reputation: 15399
As @zaitsman pointed out, I need to use the Amazon.Lambda.APIGatewayEvents
NuGet package.
I found this answer useful.
This code worked:
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!"
};
}
Upvotes: 1