Search in sources :

Example 1 with SubscribeResponse

use of software.amazon.awssdk.services.sns.model.SubscribeResponse 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 2 with SubscribeResponse

use of software.amazon.awssdk.services.sns.model.SubscribeResponse 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 3 with SubscribeResponse

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

the class SubscribeEmail method subEmail.

// snippet-start:[sns.java2.SubscribeEmail.main]
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 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 4 with SubscribeResponse

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

the class SubscribeHTTPS method subHTTPS.

// snippet-start:[sns.java2.SubscribeHTTPS.main]
public static void subHTTPS(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 is " + 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)

Aggregations

SnsException (software.amazon.awssdk.services.sns.model.SnsException)4 SubscribeRequest (software.amazon.awssdk.services.sns.model.SubscribeRequest)4 SubscribeResponse (software.amazon.awssdk.services.sns.model.SubscribeResponse)4