I have an C# AWS lambda with this signature string FunctionHandler(string input, ILambdaContext context). This lambda tested fine from the lambda web console. But when I tried invoking the same labmda from an API gateway, I receive an 500 error and also this error message in the log
Error converting the Lambda event JSON payload to a string. JSON strings must be quoted, for example "Hello World" in order to be converted to a string: Unexpected character encountered while parsing value: {. Path '', line 1, position 1.: JsonSerializerException
I've tried changing the lambda signature to this string FunctionHandler(object input, ILambdaContext context) but it did not solve the problem.
I've tried invoking a JavaScript lambda with the same API Gateway, and it is working fine.
My question is what is so special about the C# lambda that make it fail to execute behind an API Gateway?
The JavaScript lambda looks like below
exports.handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
the C# lambda looks like below
public string FunctionHandler(string input, ILambdaContext context)
{
return "hello";
}