Using Simple Notification Service (SNS) in CFML: Sending Messages
Posted 8 July 2018
Sending a message to SNS from CMFL via the AWS Java SDK is easy. You need to:
- Give your message a subject
- Give your message a body (plain text only)
- Create a PublishRequest object
- Tell your SNS client to publish your PublishRequest
If you haven’t already read the entry on the basic setup needed to access AWS from CFML, please do so now.
Here’s the relevant code from /sns.cfm in the AWSPlaybox app:
If you actually subscribed to the topic that we created in the previous post in this series (or in the AWSPlaybox app), you should get a copy of the message within seconds. Here’s what the messages look like when delivered:
SMS
You can see that in the SMS message, the text message was prefixed by the topic name. The subject value was omitted.
That’s it! It’s really quite simple to send a message to SNS via the AWS Java SDK from within your CFML application. If you are sending SMS messages, there are lots of options around price and SMS message type that you can set from within the Java SDK. You do not need to use these — they’re simply there to help you build a more robust SMS application (if that’s what you are doing).
Those are the basics of working with SNS from CMFL. In the next post, I’ll go over some caveats about working with SNS that I’ve encountered.