0

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();
        }
    }
}
Jesus is Lord
  • 14,971
  • 11
  • 66
  • 97
  • 1
    This is because you need to add API Gateway support. First, add `Amazon.Lambda.APIGatewayEvents`. Then, change your function signature to take in `APIGatewayProxyRequest request, ILambdaContext context` and return `APIGatewayProxyResponse`. – zaitsman Aug 31 '20 at 23:15

1 Answers1

1

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!"
            };
        }
Jesus is Lord
  • 14,971
  • 11
  • 66
  • 97