Search in sources :

Example 1 with SnsException

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);
    }
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient) SnsException(software.amazon.awssdk.services.sns.model.SnsException) PublishRequest(software.amazon.awssdk.services.sns.model.PublishRequest)

Example 2 with SnsException

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);
    }
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient) Region(software.amazon.awssdk.regions.Region) SnsException(software.amazon.awssdk.services.sns.model.SnsException) PublishRequest(software.amazon.awssdk.services.sns.model.PublishRequest)

Example 3 with SnsException

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);
    }
}
Also used : CheckIfPhoneNumberIsOptedOutRequest(software.amazon.awssdk.services.sns.model.CheckIfPhoneNumberIsOptedOutRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException) CheckIfPhoneNumberIsOptedOutResponse(software.amazon.awssdk.services.sns.model.CheckIfPhoneNumberIsOptedOutResponse)

Example 4 with SnsException

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 "";
}
Also used : CreateTopicRequest(software.amazon.awssdk.services.sns.model.CreateTopicRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException) CreateTopicResponse(software.amazon.awssdk.services.sns.model.CreateTopicResponse)

Example 5 with SnsException

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);
    }
}
Also used : DeleteTopicResponse(software.amazon.awssdk.services.sns.model.DeleteTopicResponse) DeleteTopicRequest(software.amazon.awssdk.services.sns.model.DeleteTopicRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException)

Aggregations

SnsException (software.amazon.awssdk.services.sns.model.SnsException)24 PublishRequest (software.amazon.awssdk.services.sns.model.PublishRequest)5 SubscribeRequest (software.amazon.awssdk.services.sns.model.SubscribeRequest)4 SubscribeResponse (software.amazon.awssdk.services.sns.model.SubscribeResponse)4 SnsClient (software.amazon.awssdk.services.sns.SnsClient)2 PublishResponse (software.amazon.awssdk.services.sns.model.PublishResponse)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Region (software.amazon.awssdk.regions.Region)1 CheckIfPhoneNumberIsOptedOutRequest (software.amazon.awssdk.services.sns.model.CheckIfPhoneNumberIsOptedOutRequest)1 CheckIfPhoneNumberIsOptedOutResponse (software.amazon.awssdk.services.sns.model.CheckIfPhoneNumberIsOptedOutResponse)1 ConfirmSubscriptionRequest (software.amazon.awssdk.services.sns.model.ConfirmSubscriptionRequest)1 ConfirmSubscriptionResponse (software.amazon.awssdk.services.sns.model.ConfirmSubscriptionResponse)1 CreateTopicRequest (software.amazon.awssdk.services.sns.model.CreateTopicRequest)1 CreateTopicResponse (software.amazon.awssdk.services.sns.model.CreateTopicResponse)1 DeleteTopicRequest (software.amazon.awssdk.services.sns.model.DeleteTopicRequest)1 DeleteTopicResponse (software.amazon.awssdk.services.sns.model.DeleteTopicResponse)1 GetSubscriptionAttributesRequest (software.amazon.awssdk.services.sns.model.GetSubscriptionAttributesRequest)1 GetSubscriptionAttributesResponse (software.amazon.awssdk.services.sns.model.GetSubscriptionAttributesResponse)1