Implementing a Java-based AWS Lambda Function triggered by SNS

I had some initial trouble finding documentation on how to consume AWS SNS events from a Lambda function implemented in Java. The signature can’t be your domain POJO it seems, it has to be a SNSEvent. Here’s what worked for me:

Maven dependencies:

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
</dependency>

The signature in the Java-based Lambda Function need to consume com.amazonaws.services.lambda.runtime.events.SNSEvent:

public String processSnsEvent(SNSEvent event, Context context) {
String input = event.getRecords().get(0).getSNS().getMessage();
return processInputFooBarSomething(input)
}

Implementing a Java-based AWS Lambda Function triggered by SNS