本文整理汇总了Java中com.amazonaws.services.sns.AmazonSNSClient.setRegion方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonSNSClient.setRegion方法的具体用法?Java AmazonSNSClient.setRegion怎么用?Java AmazonSNSClient.setRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.sns.AmazonSNSClient
的用法示例。
在下文中一共展示了AmazonSNSClient.setRegion方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
@Override
public void run(Webhook webhook, String login, String email, String name, String subject, String content) {
SNSWebhookApp webhookApp = (SNSWebhookApp) webhook.getWebhookApp();
String topicArn = webhookApp.getTopicArn();
String awsAccount = webhookApp.getAwsAccount();
String awsSecret = webhookApp.getAwsSecret();
String region = webhookApp.getRegion();
AmazonSNSClient snsClient = new AmazonSNSClient(new BasicAWSCredentials(awsAccount, awsSecret));
snsClient.setRegion(Region.getRegion(Regions.fromName(region)));
try {
PublishRequest publishReq = new PublishRequest()
.withTopicArn(topicArn)
.withMessage(getMessage(login, email, name, subject, content));
snsClient.publish(publishReq);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Cannot send notification to SNS service", e);
} finally {
LOGGER.log(Level.INFO, "Webhook runner terminated");
}
}
示例2: CreateCloudFrontSecurityGroupUpdaterLambdaOperation
import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
@Inject
public CreateCloudFrontSecurityGroupUpdaterLambdaOperation(final CloudFormationService cloudFormationService,
final EnvironmentMetadata environmentMetadata,
@Named(CF_OBJECT_MAPPER) final ObjectMapper cloudformationObjectMapper,
AWSLambda awsLambda,
AmazonS3 amazonS3) {
this.cloudFormationService = cloudFormationService;
this.cloudformationObjectMapper = cloudformationObjectMapper;
this.environmentMetadata = environmentMetadata;
this.awsLambda = awsLambda;
this.amazonS3 = amazonS3;
final Region region = Region.getRegion(Regions.US_EAST_1);
AmazonCloudFormation amazonCloudFormation = new AmazonCloudFormationClient();
amazonCloudFormation.setRegion(region);
amazonSNS = new AmazonSNSClient();
amazonSNS.setRegion(region);
}
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:20,代码来源:CreateCloudFrontSecurityGroupUpdaterLambdaOperation.java
示例3: handleRequest
import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
public String handleRequest(Context context) throws IOException {
LambdaLogger logger = context.getLogger();
logger.log("handleRequest start.");
ObjectMapper mapper = new ObjectMapper();
JsonObject json = mapper.readValue(new URL(IP_RANGE_URL), JsonObject.class);
AmazonS3Client s3 = getS3Client();
Properties props = getProperties();
s3.setEndpoint(props.getProperty("s3.endpoint"));
GetObjectRequest request = new GetObjectRequest(props.getProperty(S3_BUCKETNAME_KEY), CHECKED_FILE_NAME);
try {
S3Object beforeObject = s3.getObject(request);
InputStream is = beforeObject.getObjectContent();
JsonObject beforeJson = mapper.readValue(is, JsonObject.class);
Optional<String> diff = beforeJson.getDiff(json);
if (diff.isPresent()) {
AmazonSNSClient sns = getSNSClient();
sns.setRegion(Region.getRegion(Regions.fromName(props.getProperty("sns.region"))));
PublishRequest publishRequest = new PublishRequest(props.getProperty("sns.topic.arn"), diff.get(), SNS_SUBJECT);
PublishResult result = sns.publish(publishRequest);
logger.log("send sns message. messageId = " + result.getMessageId());
}
} catch (AmazonS3Exception e) {
logger.log("before checked-ip-ranges.json does not exist.");
}
storeCheckedIpRange(json);
logger.log("stored checked-ip-ranges.json");
return "success";
}
示例4: createSNSClient
import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
/**
* The Synchronous SNS client is used for creating topics and subscribing queues.
*/
private AmazonSNSClient createSNSClient( final Region region ) {
final UsergridAwsCredentialsProvider ugProvider = new UsergridAwsCredentialsProvider();
final AmazonSNSClient sns =
new AmazonSNSClient( ugProvider.getCredentials(), clientConfiguration );
sns.setRegion( region );
return sns;
}
示例5: amazonSNSClient
import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
protected AmazonSNS amazonSNSClient() {
AmazonSNSClient snsClient = new AmazonSNSClient(amazonCredentialsProvider());
snsClient.setRegion(getRegion());
return snsClient;
}
示例6: amazonSNSClient
import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
@Override
protected AmazonSNS amazonSNSClient() {
AmazonSNSClient snsClient = new AmazonSNSClient(awsCredentials());
snsClient.setRegion(getRegion());
return snsClient;
}
示例7: Internals
import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
private Internals() {
snsClient = new AmazonSNSClient();
snsClient.setRegion(Region.getRegion(Regions.EU_WEST_1));
}
示例8: publishToSnsTopic
import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
private void publishToSnsTopic(String topicARN, String messageBody, int badgeNum, String soundName, Boolean isDebug) throws PushSnsSenderCustomException {
theLogger.info("publishToSnsTopic has been called for topicARN:{} with messageBody:{}, badgeNum:{}, soundName:{} and isDebug:{}", topicARN, messageBody, badgeNum, soundName, isDebug);
//check th params
if (topicARN == null || messageBody == null) {
throw new PushSnsSenderCustomException("Cannot send SNS notification because topicARN or messageBody is empty!");
}
//create AWS credentials
if (awsAccessKey == null || awsSecretKey == null) {
theLogger.error("AWS credentials not configured!");
throw new PushSnsSenderCustomException("Internal server error!"); //say something via web
}
else {
awsCreds = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
}
//create a new SNS client with credentials
AmazonSNSClient snsClient = new AmazonSNSClient(awsCreds);
snsClient.setRegion(Region.getRegion(Regions.US_EAST_1));
//publish to an SNS topic
try {
//Request
PublishRequest publishRequest = new PublishRequest();
SnsAppleNotificationTemplate appleNotificationTemplate = new SnsAppleNotificationTemplate(topicARN,
messageBody,
badgeNum,
soundName,
isDebug);
publishRequest.setMessage(appleNotificationTemplate.toSnSAppleString());
publishRequest.setMessageStructure("json");
publishRequest.setTopicArn(topicARN);
PublishResult publishResult = snsClient.publish(publishRequest);
//print MessageId of message published to SNS topic
theLogger.info("MessageId: {} was successfully published", publishResult.getMessageId());
}
catch (Exception theException) {
//theLogger.error("Cannot send SNS notification! Exception: " + theException);
throw new PushSnsSenderCustomException("publishToSnsTopic: Cannot send SNS notification! Exception: " + theException);
}
finally {
snsClient.shutdown();
}
}