use of software.amazon.awssdk.services.sns.SnsClient in project aws-doc-sdk-examples by awsdocs.
the class ListOptOut method main.
public static void main(String[] args) {
SnsClient snsClient = SnsClient.builder().region(Region.US_EAST_1).build();
listOpts(snsClient);
snsClient.close();
}
use of software.amazon.awssdk.services.sns.SnsClient in project aws-doc-sdk-examples by awsdocs.
the class SubscribeHTTPS method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage: " + " <topicArn> <url>\n\n" + "Where:\n" + " topicArn - the ARN of the topic to subscribe.\n\n" + " url - the HTTPS endpoint that you want to receive notifications.\n\n";
if (args.length < 2) {
System.out.println(USAGE);
System.exit(1);
}
String topicArn = args[0];
String url = args[1];
SnsClient snsClient = SnsClient.builder().region(Region.US_WEST_2).build();
subHTTPS(snsClient, topicArn, url);
snsClient.close();
}
use of software.amazon.awssdk.services.sns.SnsClient in project aws-doc-sdk-examples by awsdocs.
the class SnsService method pubTopic.
public String pubTopic(String message, String lang) {
try {
String body;
Region region = Region.US_WEST_2;
TranslateClient translateClient = TranslateClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
if (lang.compareTo("English") == 0) {
body = message;
} else if (lang.compareTo("French") == 0) {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("fr").text(message).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
body = textResponse.translatedText();
} else {
TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("es").text(message).build();
TranslateTextResponse textResponse = translateClient.translateText(textRequest);
body = textResponse.translatedText();
}
SnsClient snsClient = getSnsClient();
PublishRequest request = PublishRequest.builder().message(body).topicArn(topicArn).build();
PublishResponse result = snsClient.publish(request);
return " Message sent in " + lang + ". Status was " + result.sdkHttpResponse().statusCode();
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "Error - msg not sent";
}
use of software.amazon.awssdk.services.sns.SnsClient in project aws-doc-sdk-examples by awsdocs.
the class SnsService method unSubEmail.
public void unSubEmail(String emailEndpoint) {
try {
String subscriptionArn = getTopicArnValue(emailEndpoint);
SnsClient snsClient = getSnsClient();
UnsubscribeRequest request = UnsubscribeRequest.builder().subscriptionArn(subscriptionArn).build();
snsClient.unsubscribe(request);
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sns.SnsClient in project aws-doc-sdk-examples by awsdocs.
the class SnsService method subEmail.
// Create a Subscription.
public String subEmail(String email) {
try {
SnsClient snsClient = getSnsClient();
SubscribeRequest request = SubscribeRequest.builder().protocol("email").endpoint(email).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 "";
}
Aggregations