Guest User

Untitled

a guest
Aug 14th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. public class SNSConfig {
  2.  
  3. public AmazonSNS sendMsg(){
  4.  
  5. AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(new ProfileCredentialsProvider());
  6. GetSessionTokenRequest getSessionTokenRequest = new GetSessionTokenRequest();
  7. getSessionTokenRequest.setDurationSeconds(7200);
  8. GetSessionTokenResult sessionTokenResult = stsClient.getSessionToken(getSessionTokenRequest);
  9. Credentials sessionCredentials = sessionTokenResult.getCredentials();
  10. BasicSessionCredentials basicSessionCredentials =
  11. new BasicSessionCredentials(sessionCredentials.getAccessKeyId(),
  12. sessionCredentials.getSecretAccessKey(),
  13. sessionCredentials.getSessionToken());
  14. AmazonSNS snsClient=AmazonSNSClient
  15. .builder()
  16. .withRegion(Regions.DEFAULT_REGION)
  17. .withCredentials(new AWSStaticCredentialsProvider(basicSessionCredentials))
  18. .build();
  19.  
  20.  
  21. return snsClient;
  22. }
  23. }
  24.  
  25. method that calls calls to send sns text:
  26. SNSConfig c = new SNSConfig();
  27.  
  28.  
  29. public void setUpSNS(String location){
  30. String msg="Customer has arrived in the "+location;
  31. String advNumber="+1210XXXXXXX";
  32.  
  33. try{
  34.  
  35. AmazonSNS sns=c.sendMsg();
  36. PublishResult result=sns.publish(new PublishRequest()
  37. .withMessage(msg)
  38. System.out.println("result:"+result);
  39. }catch(Exception e){
  40. e.printStackTrace();
  41. }
  42.  
  43.  
  44. }
Add Comment
Please, Sign In to add comment