skip to Main Content

I am trying to send a list of JSONs to be processed within a Lambda function.

I have tried several overrides on handleRequest but I have not been able to successfully get the Lambda to see it as such.

I tried…

public String handleRequest(List<String> events, Context context)

And tried in the Test tab of the Lambda function to send string formatted JSONs (will be nested) like so…

[
  jsonString1,
  jsonString2
]

But there is json exception failure that happens even before any of the Lambda code is executed. Not sure if there is some deserialization that is occurring leading to the issue.

Ultimately I want to do as specifically the documentation mentions I can do…

https://docs.aws.amazon.com/lambda/latest/dg/java-handler.html

List<Integer>, List<String>, List<Object>, etc.
The event is a JSON array.
The runtime deserializes it into an object of the specified type or interface.

2

Answers


  1. The event needs to be valid JSON.

    If you wish to send multiple JSON records, you could provide a list within the outer JSON:

    {
      my_list: [
        {"name": "This is JSON 1"},
        {"name": "This is JSON 2"},
        {"name": "This is JSON 3"}
      ]
    }
    
    Login or Signup to reply.
  2. I countered a similar issue when I worked with AWS Lambda/spring cloud function – we cannot send JSON data to Lambda because of deserialization issues so try to send your data as a hashmap or Pojo class for more information see, AWS Can not deserialize instance of java.lang.String out of START_OBJECT

    Check my code in Github, which hopefully, help you to resolve the issue.

    https://github.com/ARNR-CODE/master/blob/main/awspring/src/main/java/se/WeatherForCast/awspring/AccuWeatherHandler.java

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search