1

I suspect this may be hiding another problem but unsure what it is - I've a small Lambda function that I'm trying to test using the AWS console.

    public class ApplicationRunner implements RequestHandler<String, String> {

    static final Logger logger = Logger.getLogger(ApplicationRunner.class);

    @Override
    public String handleRequest(String input, Context context) {
    //code

}
}

The error I am receiving is:

    {
  "errorMessage": "An error occurred during JSON parsing",
  "errorType": "java.lang.RuntimeException",
  "stackTrace": [],
  "cause": {
    "errorMessage": "com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: lambdainternal.util.NativeMemoryAsInputStream@6cc4c815; line: 1, column: 1]",
    "errorType": "java.io.UncheckedIOException",
    "stackTrace": [],
    "cause": {
      "errorMessage": "Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: lambdainternal.util.NativeMemoryAsInputStream@6cc4c815; line: 1, column: 1]",
      "errorType": "com.fasterxml.jackson.databind.JsonMappingException",
      "stackTrace": [
        "com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)",
        "com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:857)",
        "com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:62)",
        "com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11)",
        "com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1511)",
        "com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1102)"
      ]
    }
  }
}

Can anyone help?

Thanks.

3
  • Your code is a little bit hazy in my crystal ball. I can't quite read it properly. Do you mind posting it here instead? Commented Aug 11, 2017 at 11:22
  • @Michael, consider your wish granted. Commented Aug 11, 2017 at 11:40
  • Can you post the input to this Lambda (the event data)? Commented Aug 11, 2017 at 12:18

1 Answer 1

2

You have:

  • rawData: data that is sent to your lambda function
  • rewrittenData: data after applying a transformation template
  • jsonData: result of json-parsing of rewriteData

The signature handleRequest(String input, Context context) means that your input is jsonData, and this JSON object is a string. Do you pass a json-string into your lambda? 99.99% that not, that you are sending an object, so you get the error message as expected.

What you want is to extend the class RequestStreamHandler and override the function with the signature:

@Override
public void handleRequest(final InputStream input, final OutputStream output, final Context context)

Now input is your rewrittenData, which is most likely the same as rawData.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.