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)
}

Advertisements
Implementing a Java-based AWS Lambda Function triggered by SNS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s