There are multiple ways to handle a Lambda event in Java. You're showing the POJO model with AWS defined POJO's where the deserialization of the object is handled for you.
However, there is also the IO Stream method. This gives you an InputStream and OutputStream to handle yourself. The code derived from the second link above could start something like:
public class Hello implements RequestStreamHandler{
public void handler(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
// copy and convert the inputStream
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
String inputString = result.toString("UTF-8");
// now try to convert to a SNSEvent using Google GSON
try {
SNSEvent snsEvent = new Gson().fromJson(inputString, SNSEvent.class);
}
catch( JsonSyntaxException jse ) {
// this is where it's weird - what if it is really bad JSON?
}
}
}
Ultimately what this does is take the JSON input, copies it to a String, and then used GSON to convert to attempt to convert to an object. You could have any number of objects that the code tries to convert to. The GSON fromJson method throws a JsonSyntaxException if it can't be converted. But it would also do that if there was totally garbage JSON so you need to be a bit careful.
I'm showing it with GSON as I've had too many weird interactions with Jackson which is what Lambda used under the covers for JSON parsing.
But this allows you to handle the InputStream yourself, deciding what to do with the input and sending your own Response in the OutputStream.