问题
java newbie.
I've compiled with java 8
javac HelloWorld.java --release 8
and uploaded the complied file as the aws lambda code.
Why am I getting the error when i run it in aws lambda?
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello, World");
}
}
Error
An error occurred during JSON parsing: java.lang.RuntimeException
java.lang.RuntimeException: An error occurred during JSON parsing
Caused by: java.io.UncheckedIOException: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
at [Source: lambdainternal.util.NativeMemoryAsInputStream@ae45eb6; line: 1, column: 1]
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
at [Source: lambdainternal.util.NativeMemoryAsInputStream@ae45eb6; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
回答1:
You're missing something fundamental here. You can't just throw a class or jar file at Lambda. There's a well-defined interface between the Lambda service and your code. Think of it this way: Lambda launches a JVM, and Lambda itself implements a Java class with the static main
method (in its code, not your code) and executes that. That main
method will ultimately call your configured Lambda function's entry point. I'd recommend this Hello World tutorial.
回答2:
AWS Lambda provides limited Java runtime to execute AWS Java Lambda handlers. The limitations are logical like access to file system, etc for security purposes as the code runs in a shared multi-tenanted environment. In order to execute a program, your class should implement the RequestHandler
interface and implement the handleRequest
method. Here is the sample from the official documentation
package example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class Hello implements RequestHandler<Integer, String>{
public String handleRequest(Integer myCount, Context context) {
return String.valueOf(myCount);
}
}
来源:https://stackoverflow.com/questions/58651788/aws-java8-can-not-deserialize-instance-of-java-lang-string-out-of-start-obje