Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SNSConfig {
- public AmazonSNS sendMsg(){
- AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(new ProfileCredentialsProvider());
- GetSessionTokenRequest getSessionTokenRequest = new GetSessionTokenRequest();
- getSessionTokenRequest.setDurationSeconds(7200);
- GetSessionTokenResult sessionTokenResult = stsClient.getSessionToken(getSessionTokenRequest);
- Credentials sessionCredentials = sessionTokenResult.getCredentials();
- BasicSessionCredentials basicSessionCredentials =
- new BasicSessionCredentials(sessionCredentials.getAccessKeyId(),
- sessionCredentials.getSecretAccessKey(),
- sessionCredentials.getSessionToken());
- AmazonSNS snsClient=AmazonSNSClient
- .builder()
- .withRegion(Regions.DEFAULT_REGION)
- .withCredentials(new AWSStaticCredentialsProvider(basicSessionCredentials))
- .build();
- return snsClient;
- }
- }
- method that calls calls to send sns text:
- SNSConfig c = new SNSConfig();
- public void setUpSNS(String location){
- String msg="Customer has arrived in the "+location;
- String advNumber="+1210XXXXXXX";
- try{
- AmazonSNS sns=c.sendMsg();
- PublishResult result=sns.publish(new PublishRequest()
- .withMessage(msg)
- System.out.println("result:"+result);
- }catch(Exception e){
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment