AWS SNS using JDK – code sample
As with many programming blog posts, this one is the product of an inordinate amount of time trying to dig up pieces of a puzzle, which one would have thought to be straight forward.
This example is written for ColdFusion, but as you can see, the meat can be done using Java directly and maybe other languages as well.
First off, we need an AWS SNS “topic” which might otherwise be called a modern listserve on steroids. It supports email, sns and other input/output interfaces. Setting one up is fairly straightforward, so I won’t bother with much here.
As of this writing, the AWS Java SDK is up to 1.11.203 and changing almost every day (see here for full listing on GH). Our organization (and this code) is currently using 1.11.132 however, available here from AWS via GitHub. NOTE: the zip file does not have the *.java files which are required for the next steps so use the *tar.jz!
A few points about the AWS JDK:
- In the online JDK javaDocs, despite the fact that the frame navigation for amazonSNSClient is listed, it is basically completely depracated and replaced by AmazonSNSClientBuilder. See here for why this is, and why its better.
- I’m not a java person, but I found it very frustrating trying to find javadocs on this version. AFIK there were none! Every link i found ultimatley lead me to “latest” folder. So my solution was to extract the whole jar file, use the command line to step into that folder and run the following code:
find . -type f -name "*.java" | xargs javadoc -Xdoclint:none -d outputdir
But even that didn’t work! Javadoc threw all kinds of errors and only generated part of the outptu. So, ultimately I left with just browsing into the sns folder itself and running that command. The result can be found here: aws-java-sdk-1.11.132-SNS-javadocs.
So, here’s the code. More lines than the older “client” api required, but we’re told it’s better.
https://gist.github.com/obxpete/341785005f3fb885d4732a3a90bcebab
Props to Simon Hooker’s post for helping me get started.