Search in sources :

Example 1 with PublishRequest

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

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

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

the class PublishTopic method pubTopic.

// snippet-start:[sns.java2.PublishTopic.main]
public static void pubTopic(SnsClient snsClient, String message, String topicArn) {
    try {
        PublishRequest request = PublishRequest.builder().message(message).topicArn(topicArn).build();
        PublishResponse result = snsClient.publish(request);
        System.out.println(result.messageId() + " Message sent. Status is " + result.sdkHttpResponse().statusCode());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : PublishResponse(software.amazon.awssdk.services.sns.model.PublishResponse) SnsException(software.amazon.awssdk.services.sns.model.SnsException) PublishRequest(software.amazon.awssdk.services.sns.model.PublishRequest)

Example 4 with PublishRequest

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

the class PublishTextSMS method pubTextSMS.

// snippet-start:[sns.java2.PublishTextSMS.main]
public static void pubTextSMS(SnsClient snsClient, String message, String phoneNumber) {
    try {
        PublishRequest request = PublishRequest.builder().message(message).phoneNumber(phoneNumber).build();
        PublishResponse result = snsClient.publish(request);
        System.out.println(result.messageId() + " Message sent. Status was " + result.sdkHttpResponse().statusCode());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : PublishResponse(software.amazon.awssdk.services.sns.model.PublishResponse) SnsException(software.amazon.awssdk.services.sns.model.SnsException) PublishRequest(software.amazon.awssdk.services.sns.model.PublishRequest)

Example 5 with PublishRequest

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

PublishRequest (software.amazon.awssdk.services.sns.model.PublishRequest)5 SnsException (software.amazon.awssdk.services.sns.model.SnsException)5 SnsClient (software.amazon.awssdk.services.sns.SnsClient)2 PublishResponse (software.amazon.awssdk.services.sns.model.PublishResponse)2 Region (software.amazon.awssdk.regions.Region)1