Search in sources :

Example 16 with SnsException

use of software.amazon.awssdk.services.sns.model.SnsException in project aws-doc-sdk-examples by awsdocs.

the class SetTopicAttributes method setTopAttr.

// snippet-start:[sns.java2.SetTopicAttributes.main]
public static void setTopAttr(SnsClient snsClient, String attribute, String topicArn, String value) {
    try {
        SetTopicAttributesRequest request = SetTopicAttributesRequest.builder().attributeName(attribute).attributeValue(value).topicArn(topicArn).build();
        SetTopicAttributesResponse result = snsClient.setTopicAttributes(request);
        System.out.println("\n\nStatus was " + result.sdkHttpResponse().statusCode() + "\n\nTopic " + request.topicArn() + " updated " + request.attributeName() + " to " + request.attributeValue());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SetTopicAttributesResponse(software.amazon.awssdk.services.sns.model.SetTopicAttributesResponse) SetTopicAttributesRequest(software.amazon.awssdk.services.sns.model.SetTopicAttributesRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException)

Example 17 with SnsException

use of software.amazon.awssdk.services.sns.model.SnsException in project aws-doc-sdk-examples by awsdocs.

the class SubscribeLambda method subLambda.

// snippet-start:[sns.java2.SubscribeLambda.main]
public static String subLambda(SnsClient snsClient, String topicArn, String lambdaArn) {
    try {
        SubscribeRequest request = SubscribeRequest.builder().protocol("lambda").endpoint(lambdaArn).returnSubscriptionArn(true).topicArn(topicArn).build();
        SubscribeResponse result = snsClient.subscribe(request);
        return result.subscriptionArn();
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : SubscribeRequest(software.amazon.awssdk.services.sns.model.SubscribeRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException) SubscribeResponse(software.amazon.awssdk.services.sns.model.SubscribeResponse)

Example 18 with SnsException

use of software.amazon.awssdk.services.sns.model.SnsException in project aws-doc-sdk-examples by awsdocs.

the class SubscribeTextSMS method subTextSNS.

// snippet-start:[sns.java2.SubscribeTextSMS.main]
public static void subTextSNS(SnsClient snsClient, String topicArn, String phoneNumber) {
    try {
        SubscribeRequest request = SubscribeRequest.builder().protocol("sms").endpoint(phoneNumber).returnSubscriptionArn(true).topicArn(topicArn).build();
        SubscribeResponse result = snsClient.subscribe(request);
        System.out.println("Subscription ARN: " + result.subscriptionArn() + "\n\n Status is " + result.sdkHttpResponse().statusCode());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SubscribeRequest(software.amazon.awssdk.services.sns.model.SubscribeRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException) SubscribeResponse(software.amazon.awssdk.services.sns.model.SubscribeResponse)

Example 19 with SnsException

use of software.amazon.awssdk.services.sns.model.SnsException in project aws-doc-sdk-examples by awsdocs.

the class Unsubscribe method unSub.

// snippet-start:[sns.java2.Unsubscribe.main]
public static void unSub(SnsClient snsClient, String subscriptionArn) {
    try {
        UnsubscribeRequest request = UnsubscribeRequest.builder().subscriptionArn(subscriptionArn).build();
        UnsubscribeResponse result = snsClient.unsubscribe(request);
        System.out.println("\n\nStatus was " + result.sdkHttpResponse().statusCode() + "\n\nSubscription was removed for " + request.subscriptionArn());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : UnsubscribeRequest(software.amazon.awssdk.services.sns.model.UnsubscribeRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException) UnsubscribeResponse(software.amazon.awssdk.services.sns.model.UnsubscribeResponse)

Example 20 with SnsException

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

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