use of software.amazon.awssdk.services.sns.model.PublishRequest in project aws-doc-sdk-examples by awsdocs.
the class ScanEmployees method sentTextMessage.
// Use the Amazon SNS Service to send a text message
private void sentTextMessage(String first, String phone) {
SnsClient snsClient = SnsClient.builder().region(Region.US_WEST_2).build();
String message = first + " happy one year anniversary. We are very happy that you have been working here for a year! ";
try {
PublishRequest request = PublishRequest.builder().message(message).phoneNumber(phone).build();
snsClient.publish(request);
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sns.model.PublishRequest in project aws-doc-sdk-examples by awsdocs.
the class PublishTextSMS method sendMessage.
public void sendMessage(String id) {
Region region = Region.US_EAST_1;
SnsClient snsClient = SnsClient.builder().region(region).credentialsProvider(EnvironmentVariableCredentialsProvider.create()).build();
String message = "A new item with ID value " + id + " was added to the DynamoDB table";
// Replace with a mobile phone number
String phoneNumber = "18195765654";
try {
PublishRequest request = PublishRequest.builder().message(message).phoneNumber(phoneNumber).build();
snsClient.publish(request);
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sns.model.PublishRequest in project aws-doc-sdk-examples by awsdocs.
the class PublishTopic method pubTopic.
// snippet-start:[sns.java2.PublishTopic.main]
public static void pubTopic(SnsClient snsClient, String message, String topicArn) {
try {
PublishRequest request = PublishRequest.builder().message(message).topicArn(topicArn).build();
PublishResponse result = snsClient.publish(request);
System.out.println(result.messageId() + " Message sent. Status is " + result.sdkHttpResponse().statusCode());
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sns.model.PublishRequest in project aws-doc-sdk-examples by awsdocs.
the class PublishTextSMS method pubTextSMS.
// snippet-start:[sns.java2.PublishTextSMS.main]
public static void pubTextSMS(SnsClient snsClient, String message, String phoneNumber) {
try {
PublishRequest request = PublishRequest.builder().message(message).phoneNumber(phoneNumber).build();
PublishResponse result = snsClient.publish(request);
System.out.println(result.messageId() + " Message sent. Status was " + result.sdkHttpResponse().statusCode());
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sns.model.PublishRequest in project aws-doc-sdk-examples by awsdocs.
the class SendNotifications method publishTextSMS.
private void publishTextSMS(SnsClient snsClient, String phoneNumber) {
String message = "Please be advised that your student was marked absent from school today.";
try {
PublishRequest request = PublishRequest.builder().message(message).phoneNumber(phoneNumber).build();
snsClient.publish(request);
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations