use of software.amazon.awssdk.services.sns.model.SnsException 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.SnsException 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.SnsException in project aws-doc-sdk-examples by awsdocs.
the class CheckOptOut method checkPhone.
// snippet-start:[sns.java2.CheckOptOut.main]
public static void checkPhone(SnsClient snsClient, String phoneNumber) {
try {
CheckIfPhoneNumberIsOptedOutRequest request = CheckIfPhoneNumberIsOptedOutRequest.builder().phoneNumber(phoneNumber).build();
CheckIfPhoneNumberIsOptedOutResponse result = snsClient.checkIfPhoneNumberIsOptedOut(request);
System.out.println(result.isOptedOut() + "Phone Number " + phoneNumber + " has Opted Out of receiving sns messages." + "\n\nStatus was " + result.sdkHttpResponse().statusCode());
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sns.model.SnsException in project aws-doc-sdk-examples by awsdocs.
the class CreateTopic method createSNSTopic.
// snippet-start:[sns.java2.CreateTopic.main]
public static String createSNSTopic(SnsClient snsClient, String topicName) {
CreateTopicResponse result = null;
try {
CreateTopicRequest request = CreateTopicRequest.builder().name(topicName).build();
result = snsClient.createTopic(request);
return result.topicArn();
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.sns.model.SnsException in project aws-doc-sdk-examples by awsdocs.
the class DeleteTopic method deleteSNSTopic.
// snippet-start:[sns.java2.DeleteTopic.main]
public static void deleteSNSTopic(SnsClient snsClient, String topicArn) {
try {
DeleteTopicRequest request = DeleteTopicRequest.builder().topicArn(topicArn).build();
DeleteTopicResponse result = snsClient.deleteTopic(request);
System.out.println("\n\nStatus was " + result.sdkHttpResponse().statusCode());
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations