List of usage examples for com.amazonaws.regions Region getRegion
public static Region getRegion(Regions region)
From source file:model.data.location.FileAccessFactory.java
License:Apache License
/** * Gets the input stream for an S3 file store. This will stream the bytes from S3. Null, or exception will be thrown * if an error occurs during acquisition. * /*from w w w . j ava 2 s . co m*/ * The S3 Credentials MUST be populated using the setCredentials() method before executing this call, or a * Credentials exception is likely to be thrown by S3. */ @JsonIgnore public InputStream getS3File(FileLocation fileLocation, String accessKey, String privateKey, String s3EncryptKey) { // Get the file from S3. Connect to S3 Bucket. Only apply credentials if they are present. final AmazonS3Client s3Client; S3FileStore fileStore = (S3FileStore) fileLocation; if (accessKey.isEmpty() || privateKey.isEmpty()) { s3Client = new AmazonS3Client(); } else { // If an encryption key was provided, use the encrypted client BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, privateKey); if (s3EncryptKey != null) { KMSEncryptionMaterialsProvider materialProvider = new KMSEncryptionMaterialsProvider(s3EncryptKey); s3Client = new AmazonS3EncryptionClient(credentials, materialProvider, new CryptoConfiguration().withKmsRegion(Regions.US_EAST_1)) .withRegion(Region.getRegion(Regions.US_EAST_1)); } else { s3Client = new AmazonS3Client(credentials); } } S3Object s3Object = s3Client.getObject(fileStore.getBucketName(), fileStore.getFileName()); return s3Object.getObjectContent(); }
From source file:mx.iteso.desi.cloud.keyvalue.DynamoDBStorage.java
License:Apache License
public DynamoDBStorage(String dbName) { BasicAWSCredentials cred = new BasicAWSCredentials(Config.accessKeyID, Config.secretAccessKey); if (Config.DynamoDbClientType == Config.DYNAMODBCLIENTTYPE.Local) { client = new AmazonDynamoDBClient(cred); client.setRegion(Region.getRegion(Config.amazonRegion)); client.setEndpoint("http://localhost:8000"); } else {/*from w w w . j a v a2 s . com*/ client = AmazonDynamoDBClientBuilder.standard().withRegion(Config.amazonRegion) .withCredentials(new AWSStaticCredentialsProvider(cred)).build(); } docClient = new DynamoDB(client); this.dbName = dbName; // Create a table CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(dbName) .withKeySchema(new KeySchemaElement().withAttributeName("keyword").withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName("inx").withKeyType(KeyType.RANGE)) .withAttributeDefinitions( new AttributeDefinition().withAttributeName("keyword") .withAttributeType(ScalarAttributeType.S), new AttributeDefinition().withAttributeName("inx").withAttributeType(ScalarAttributeType.N)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); // Create table if it does not exist yet TableUtils.createTableIfNotExists(client, createTableRequest); // Wait for the table to move into Active state try { TableUtils.waitUntilActive(client, dbName); } catch (Exception e) { // Do nothing... yet } //requestItems.put(dbName, requestList); }
From source file:net.lizhaoweb.aws.api.service.impl.SNSNotificationHandlerForCloudSearch.java
License:Open Source License
private Region getRegion(S3EventMessageRecord snsMessageRecord) { if (snsMessageRecord == null) { return null; }//from w w w .j av a2 s . c om String awsRegion = snsMessageRecord.getAwsRegion(); if (StringUtil.isEmpty(awsRegion)) { return null; } Regions regions = null; try { regions = Regions.fromName(awsRegion); } catch (Exception e) { return null; } Region region = Region.getRegion(regions); return region; }
From source file:net.lizhaoweb.aws.api.SNSAPI.java
License:Open Source License
/** * // ww w. ja v a2 s . co m * * @param regionString * @param topicRequest * @return ?? */ @RequestMapping(value = "/{" + PathVariableKey.REGION + "}/topic", method = { RequestMethod.POST }) @ResponseBody public DataDeliveryWrapper<CreateTopicResult> createTopic( @PathVariable(PathVariableKey.REGION) String regionString, @ModelAttribute("topic") SNSTopicRequest topicRequest) { if (StringUtil.isEmpty(regionString)) { return new DataDeliveryWrapper<CreateTopicResult>(HttpStatus.SC_NOT_FOUND, "", null); } else if (StringUtil.isEmpty(topicRequest.getSnsName())) { return new DataDeliveryWrapper<CreateTopicResult>(HttpStatus.SC_NOT_FOUND, "??", null); } Regions regions = null; try { regions = Regions.fromName(regionString); } catch (Exception e) { return new DataDeliveryWrapper<CreateTopicResult>(HttpStatus.SC_FORBIDDEN, "", null); } if (topicRequest.getAttributeName() == null) { topicRequest.setAttributeName(""); } if (topicRequest.getAttributeValue() == null) { topicRequest.setAttributeValue(""); } try { Region region = Region.getRegion(regions); topicRequest.setRegion(region); AmazonSNS client = snsService.getAmazonSNSClient(region); CreateTopicResult result = snsService.createTopic(client, topicRequest); return new DataDeliveryWrapper<CreateTopicResult>(HttpStatus.SC_OK, "?", result); } catch (Exception e) { String errorMessage = ""; logger.error(errorMessage, e); return new DataDeliveryWrapper<CreateTopicResult>(HttpStatus.SC_INTERNAL_SERVER_ERROR, errorMessage, null); } }
From source file:net.lizhaoweb.aws.api.SNSAPI.java
License:Open Source License
/** * //w w w. j a va 2s . c o m * * @param regionString * @param subscribingTopicRequest * @return ?? */ @RequestMapping(value = "/{" + PathVariableKey.REGION + "}/topic/subscribing", method = { RequestMethod.POST }) @ResponseBody public DataDeliveryWrapper<SubscribeResult> subscribingTopic( @PathVariable(PathVariableKey.REGION) String regionString, @ModelAttribute("subscribingTopic") SNSSubscribingTopicRequest subscribingTopicRequest) { if (StringUtil.isEmpty(regionString)) { return new DataDeliveryWrapper<SubscribeResult>(HttpStatus.SC_NOT_FOUND, "", null); } else if (StringUtil.isEmpty(subscribingTopicRequest.getTopicArn())) { return new DataDeliveryWrapper<SubscribeResult>(HttpStatus.SC_NOT_FOUND, "?", null); } else if (StringUtil.isEmpty(subscribingTopicRequest.getProtocol())) { return new DataDeliveryWrapper<SubscribeResult>(HttpStatus.SC_NOT_FOUND, "??", null); } else if (StringUtil.isEmpty(subscribingTopicRequest.getEndpoint())) { return new DataDeliveryWrapper<SubscribeResult>(HttpStatus.SC_NOT_FOUND, "?", null); } Regions regions = null; try { regions = Regions.fromName(regionString); } catch (Exception e) { return new DataDeliveryWrapper<SubscribeResult>(HttpStatus.SC_FORBIDDEN, "", null); } try { Region region = Region.getRegion(regions); subscribingTopicRequest.setRegion(region); AmazonSNS client = snsService.getAmazonSNSClient(region); SubscribeResult result = snsService.subscribingTopic(client, subscribingTopicRequest); return new DataDeliveryWrapper<SubscribeResult>(HttpStatus.SC_OK, "?", result); } catch (Exception e) { String errorMessage = ""; logger.error(errorMessage, e); return new DataDeliveryWrapper<SubscribeResult>(HttpStatus.SC_INTERNAL_SERVER_ERROR, errorMessage, null); } }
From source file:net.lizhaoweb.aws.api.SNSAPI.java
License:Open Source License
/** * ???//from w w w .j ava 2s .c om * * @param regionString * @param publish2TopicRequest * @return ?? */ @RequestMapping(value = "/{" + PathVariableKey.REGION + "}/topic", method = { RequestMethod.PUT }) @ResponseBody public DataDeliveryWrapper<PublishResult> publish2Topic( @PathVariable(PathVariableKey.REGION) String regionString, @ModelAttribute("publish2Topic") SNSPublish2TopicRequest publish2TopicRequest) { if (StringUtil.isEmpty(regionString)) { return new DataDeliveryWrapper<PublishResult>(HttpStatus.SC_NOT_FOUND, "", null); } else if (StringUtil.isEmpty(publish2TopicRequest.getTopicArn())) { return new DataDeliveryWrapper<PublishResult>(HttpStatus.SC_NOT_FOUND, "?", null); } else if (StringUtil.isEmpty(publish2TopicRequest.getMessage())) { return new DataDeliveryWrapper<PublishResult>(HttpStatus.SC_NOT_FOUND, "?", null); } Regions regions = null; try { regions = Regions.fromName(regionString); } catch (Exception e) { return new DataDeliveryWrapper<PublishResult>(HttpStatus.SC_FORBIDDEN, "", null); } try { Region region = Region.getRegion(regions); publish2TopicRequest.setRegion(region); AmazonSNS client = snsService.getAmazonSNSClient(region); PublishResult result = snsService.publish2Topic(client, publish2TopicRequest); return new DataDeliveryWrapper<PublishResult>(HttpStatus.SC_OK, "????", result); } catch (Exception e) { String errorMessage = "???"; logger.error(errorMessage, e); return new DataDeliveryWrapper<PublishResult>(HttpStatus.SC_INTERNAL_SERVER_ERROR, errorMessage, null); } }
From source file:net.lizhaoweb.aws.api.SNSAPI.java
License:Open Source License
/** * /* ww w. j a v a 2s . c o m*/ * * @param regionString * @param topicRequest * @return ?? */ @RequestMapping(value = "/{" + PathVariableKey.REGION + "}/topic", method = { RequestMethod.DELETE }) @ResponseBody public DataDeliveryWrapper<DeleteTopicResult> deleteTopic( @PathVariable(PathVariableKey.REGION) String regionString, @ModelAttribute("topic") SNSTopicRequest topicRequest) { if (StringUtil.isEmpty(regionString)) { return new DataDeliveryWrapper<DeleteTopicResult>(HttpStatus.SC_NOT_FOUND, "", null); } else if (StringUtil.isEmpty(topicRequest.getTopicArn())) { return new DataDeliveryWrapper<DeleteTopicResult>(HttpStatus.SC_NOT_FOUND, "?", null); } Regions regions = null; try { regions = Regions.fromName(regionString); } catch (Exception e) { return new DataDeliveryWrapper<DeleteTopicResult>(HttpStatus.SC_FORBIDDEN, "", null); } try { Region region = Region.getRegion(regions); topicRequest.setRegion(region); // DeleteTopicResult deleteTopicResult = AmazonSNS client = snsService.getAmazonSNSClient(region); snsService.deleteTopic(client, topicRequest); return new DataDeliveryWrapper<DeleteTopicResult>(HttpStatus.SC_OK, "?", null); } catch (Exception e) { String errorMessage = ""; logger.error(errorMessage, e); return new DataDeliveryWrapper<DeleteTopicResult>(HttpStatus.SC_INTERNAL_SERVER_ERROR, errorMessage, null); } }
From source file:net.lizhaoweb.aws.api.SNSAPI.java
License:Open Source License
/** * //from w ww. j a v a 2 s .c om * * @param regionString * @param platformEndpointRequest ? * @return ?? */ @RequestMapping(value = "/{" + PathVariableKey.REGION + "}/platform_endpoint", method = { RequestMethod.POST }) @ResponseBody public DataDeliveryWrapper<CreatePlatformEndpointResult> deleteTopic( @PathVariable(PathVariableKey.REGION) String regionString, @ModelAttribute("platformEndpoint") SNSPlatformEndpointRequest platformEndpointRequest) { if (StringUtil.isEmpty(regionString)) { return new DataDeliveryWrapper<CreatePlatformEndpointResult>(HttpStatus.SC_NOT_FOUND, "", null); } else if (StringUtil.isEmpty(platformEndpointRequest.getToken())) { return new DataDeliveryWrapper<CreatePlatformEndpointResult>(HttpStatus.SC_NOT_FOUND, "", null); } else if (StringUtil.isEmpty(platformEndpointRequest.getPlatformApplicationArn())) { return new DataDeliveryWrapper<CreatePlatformEndpointResult>(HttpStatus.SC_NOT_FOUND, "???", null); } Regions regions = null; try { regions = Regions.fromName(regionString); } catch (Exception e) { return new DataDeliveryWrapper<CreatePlatformEndpointResult>(HttpStatus.SC_FORBIDDEN, "", null); } try { Region region = Region.getRegion(regions); platformEndpointRequest.setRegion(region); AmazonSNS client = snsService.getAmazonSNSClient(region); // DeleteTopicResult deleteTopicResult = CreatePlatformEndpointResult result = snsService.createPlatformEndpoint(client, platformEndpointRequest); return new DataDeliveryWrapper<CreatePlatformEndpointResult>(HttpStatus.SC_OK, "??", result); } catch (Exception e) { String errorMessage = "?"; logger.error(errorMessage, e); return new DataDeliveryWrapper<CreatePlatformEndpointResult>(HttpStatus.SC_INTERNAL_SERVER_ERROR, errorMessage, null); } }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public String createTopic(INotificationEndpoint notificationEndpoint) { Preconditions.checkArgument((notificationEndpoint != null), "Notification endpoint must not be null"); Preconditions.checkArgument((notificationEndpoint.getTopicArn() == null), "Notification already has a notification URL defined"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1);/*from www . j av a 2s .c o m*/ String topicArn = null; try { String topicName = stripUrnUuidPrefix(notificationEndpoint.getAccount()); LOG.info("Topic Name Assigned: " + topicName); CreateTopicRequest request = new CreateTopicRequest(topicName); CreateTopicResult result = sns.createTopic(request); topicArn = result.getTopicArn(); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), result.getTopicArn()); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationEnroll, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } return topicArn; }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public String subscribe(INotificationEndpoint notificationEndpoint) { String subscriptionArn;//from www .j a va2s . com Preconditions.checkArgument((notificationEndpoint != null), "Notification endpoint must not be null"); Preconditions.checkArgument((notificationEndpoint.getTopicArn() != null), "Notification Topic ARN must not be null"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1); try { SubscribeRequest request = new SubscribeRequest(notificationEndpoint.getTopicArn(), "https", notificationEndpoint.getNotificationEndpointUrl()); SubscribeResult result = sns.subscribe(request); subscriptionArn = result.getSubscriptionArn(); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), result.getSubscriptionArn()); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationSubscribe, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } return subscriptionArn; }