-1

When trying to test my AWS REST API POST method that's connected to my Java Lambda function, I get an error {"message": "Internal server error"} when I pass in: userID=5&name=test as a query string like so: enter image description here

I want to do the same as thing as going into Lambda Test console and typing in:

{
  "userID": 5
  "name": "test"
}

in the "Event JSON" part (which works fine in Lambda), but when I try to replicate it through the API, it doesn't work.

This is my Java code:

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.amazonaws.services.lambda.runtime.RequestHandler;

public class Launcher implements RequestHandler<Launcher.CompanyRecord, String>{

    public String handleRequest(CompanyRecord event, Context context) {
        return String.valueOf(event.userID) + event.name;
    }

    record CompanyRecord(int userID, String name) {
    }
}

I've also tried passing in

{
  "userID": 10,
  "name": "test"
}

in the Headers and Request Body (independently), but I still get the same {"message": "Internal server error"}

boundliss
  • 1
  • 1
  • More info about your request would be helpful. You say you 'pass in a query string'. Is that as part of the URL? A message body? What mime-type are you sending? What client are you using to send the request? Similar questions may help clarify: https://stackoverflow.com/questions/32057053/how-to-pass-a-params-from-post-to-aws-lambda-from-amazon-api-gateway – cmonkey Aug 08 '23 at 18:29
  • Have you checked the logs? It should show the stacktrace. – Abhijit Sarkar Aug 08 '23 at 18:47
  • @cmonkey - I edited the post to add a picture to detail exactly what I did. I hope that clarifies what I did – boundliss Aug 08 '23 at 18:51
  • @AbhijitSarkar Yes, I'm getting an error: "Execution failed due to configuration error: Malformed Lambda proxy response" – boundliss Aug 08 '23 at 18:53

1 Answers1

0

I found the mistake. I had "Use Lambda Proxy integration" on when creating the method. After turning it off, it worked when I put the JSON in the request body of the POST request like so: enter image description here

boundliss
  • 1
  • 1