daily pastebin goal
49%
SHARE
TWEET

Untitled

a guest Aug 14th, 2018 58 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top