- Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathAmazonSNSSender.java
More file actions
Latest commit
39 lines (30 loc) · 1.28 KB
/
Copy pathAmazonSNSSender.java
File metadata and controls
39 lines (30 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
importjava.util.Date;
importcom.amazonaws.auth.AWSCredentials;
importcom.amazonaws.auth.BasicAWSCredentials;
importcom.amazonaws.services.sns.AmazonSNSClient;
importcom.amazonaws.services.sns.model.CreateTopicRequest;
importcom.amazonaws.services.sns.model.CreateTopicResult;
importcom.amazonaws.services.sns.model.PublishRequest;
// Example SNS Sender
publicclassAmazonSNSSender {
// AWS credentials -- replace with your credentials
staticStringACCESS_KEY = "<Your AWS Access Key>";
staticStringSECRET_KEY = "<Your AWS Secret Key>";
// Sender loop
publicstaticvoidmain(String... args) throwsException {
// Create a client
AmazonSNSClientservice = newAmazonSNSClient(newBasicAWSCredentials(ACCESS_KEY, SECRET_KEY));
// Create a topic
CreateTopicRequestcreateReq = newCreateTopicRequest()
.withName("MyTopic");
CreateTopicResultcreateRes = service.createTopic(createReq);
for (;;) {
// Publish to a topic
PublishRequestpublishReq = newPublishRequest()
.withTopicArn(createRes.getTopicArn())
.withMessage("Example notification sent at " + newDate());
service.publish(publishReq);
Thread.sleep(1000);
}
}
}