AWS SNS allows us to send a message to a notification topic, and have that message propagated to
-
SQS queues
-
Email
-
Mobile
-
Text Messages
1. creating the topic
A simple SNS topic can be done with the following Cloudformation template:
Simple SNS topic
Resources:
SnsTopic:
Type: "AWS::SNS::Topic"
Properties:
DisplayName: MySNSTopic
Subscription:
-
Protocol: email
Endpoint: orlando.karam@gmail.com
-
Protocol: sqs
Endpoint: !ImportValue TheQueueArn
- Protocol: sms
Endpoint: 4044219151
TopicName: MySNSTopic
2. Publishing to a topic
publish.groovy
@Grab('com.amazonaws:aws-java-sdk-core:+')
import com.amazonaws.services.sns.AmazonSNSClient;
@Grab('com.amazonaws:aws-java-sdk-sns:+')
import com.amazonaws.services.sns.model.*;
def topic_arn=args[0]
def message=args[1]
AmazonSNSClient client=new AmazonSNSClient();
client.publish(topic_arn, message);