Java Code Examples for software.amazon.awssdk.services.sns.SnsClient#subscribe()

The following examples show how to use software.amazon.awssdk.services.sns.SnsClient#subscribe() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubscribeLambda.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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 "";
     //snippet-end:[sns.java2.SubscribeLambda.main]
    }
 
Example 2
Source File: SubscribeTextSMS.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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 was " + result.sdkHttpResponse().statusCode());

    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
        //snippet-end:[sns.java2.SubscribeTextSMS.main]
    }
 
Example 3
Source File: SubscribeHTTPS.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void subHTTS(SnsClient snsClient, String topicArn, String url ) {

        try {
            SubscribeRequest request = SubscribeRequest.builder()
                .protocol("http")
                .endpoint(url)
                .returnSubscriptionArn(true)
                .topicArn(topicArn)
                .build();

            SubscribeResponse result = snsClient.subscribe(request);
            System.out.println("Subscription ARN: " + result.subscriptionArn() + "\n\n Status was " + result.sdkHttpResponse().statusCode());

        } catch (SnsException e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
         }

        //snippet-end:[sns.java2.SubscribeHTTPS.main]
    }
 
Example 4
Source File: SubscribeEmail.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void subEmail(SnsClient snsClient, String topicArn, String email) {

        try {
            SubscribeRequest request = SubscribeRequest.builder()
                .protocol("email")
                .endpoint(email)
                .returnSubscriptionArn(true)
                .topicArn(topicArn)
                .build();

            SubscribeResponse result = snsClient.subscribe(request);
            System.out.println("Subscription ARN: " + result.subscriptionArn() + "\n\n Status was " + result.sdkHttpResponse().statusCode());

        } catch (SnsException e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
        //snippet-end:[sns.java2.SubscribeEmail.main]
    }