List of usage examples for com.amazonaws.regions Region getRegion
public static Region getRegion(Regions region)
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public void deleteTopic(INotificationEndpoint notificationEndpoint) { 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);/*from w w w. j a v a2 s . c o m*/ try { DeleteTopicRequest request = new DeleteTopicRequest(notificationEndpoint.getTopicArn()); sns.deleteTopic(request); } finally { sns.shutdown(); } // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), ""); IEventService eventService = context.getServiceFactory().getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationWithdrawn, notificationEndpoint.getAccount(), null, nro); }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public void publish(INotificationEndpoint notificationEndpoint, String json) { Preconditions.checkArgument((notificationEndpoint != null), "Endpoint must not be null"); Preconditions.checkArgument((notificationEndpoint.getTopicArn() != null), "Endpoint is missing a notification URL definition"); Preconditions.checkArgument((!notificationEndpoint.isPendingConfirmation()), "Endpoint has not yet been confirmed"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1);//from ww w.j a va 2s . c o m try { String subject = "SMART COSMOS Objects Event Notification"; JSONObject jsonObject = null; try { jsonObject = new JSONObject(json); if (jsonObject.has(EVENT_TYPE)) { String eventType = jsonObject.getString(EVENT_TYPE); subject = "Objects Event: " + eventType; } } catch (JSONException e) { e.printStackTrace(); } PublishRequest request = new PublishRequest(notificationEndpoint.getTopicArn(), json, subject); PublishResult result = sns.publish(request); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), result.getMessageId()); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationBroadcast, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public void unsubscribe(INotificationEndpoint notificationEndpoint) { Preconditions.checkArgument((notificationEndpoint != null), "Notification endpoint must not be null"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1);// w ww . j a v a 2s . com try { UnsubscribeRequest request = new UnsubscribeRequest(notificationEndpoint.getSubscriptionArn()); sns.unsubscribe(request); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), ""); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationUnsubscribe, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public void confirmSubscription(INotificationEndpoint notificationEndpoint, String token) { 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);/*from w w w .ja v a2 s .co m*/ try { ConfirmSubscriptionRequest request = new ConfirmSubscriptionRequest(notificationEndpoint.getTopicArn(), token); ConfirmSubscriptionResult result = sns.confirmSubscription(request); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), result.getSubscriptionArn()); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationSubscriptionConfirmed, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public boolean isHealthy() { try {//ww w.j a v a 2 s. com AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1); sns.listTopics(); return true; } catch (Exception e) { return false; } }
From source file:net.smartcosmos.plugin.service.aws.queue.AwsQueueService.java
License:Apache License
private Region assignRegion(AmazonSQS sqs) { String regionName = context.getConfiguration().getServiceParameters() .get(SERVICE_PARAM_QUEUE_SERVICE_REGION); if (regionName != null) { try {/* w w w. ja va 2s . c om*/ Regions region = Regions.fromName(regionName); Region queueRegion = Region.getRegion(region); sqs.setRegion(queueRegion); LOG.debug("Using region " + regionName); return queueRegion; } catch (Exception e) { // Default to the US_EAST_1 region sqs.setRegion(Region.getRegion(Regions.US_EAST_1)); LOG.warn("Using region US_EAST_1 as a result of an exception: " + e.getMessage()); } } else { // Default to the US_EAST_1 region sqs.setRegion(Region.getRegion(Regions.US_EAST_1)); LOG.info("Using default region of US_EAST_1"); } return Region.getRegion(Regions.US_EAST_1); }
From source file:nyu.twitter.lg.FentchTwitter.java
License:Open Source License
/** * The only information needed to create a client are security credentials * consisting of the AWS Access Key ID and Secret Access Key. All other * configuration, such as the service endpoints, are performed * automatically. Client parameters, such as proxies, can be specified in an * optional ClientConfiguration object when constructing a client. * * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration *//* w ww .j av a2 s . c o m*/ private static void init() throws Exception { /* * The ProfileCredentialsProvider will return your [New US East * (Virginia) Profile] credential profile by reading from the * credentials file located at (). */ // AWSCredentials credentials = null; AWSCredentialsProvider credentialsProvider = null; try { credentialsProvider = new ClasspathPropertiesFileCredentialsProvider(); // credentials = new ProfileCredentialsProvider( // "New US East (Virginia) Profile").getCredentials(); } catch (Exception e) { throw new AmazonClientException( // "Cannot load the credentials from the credential profiles file. " // + "Please make sure that your credentials file is at the correct " // + "location (), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentialsProvider); Region usEast1 = Region.getRegion(Regions.US_EAST_1); dynamoDB.setRegion(usEast1); }
From source file:onl.area51.filesystem.s3.AbstractS3Action.java
License:Apache License
public AbstractS3Action(FileSystemIO delegate, Map<String, ?> env) { this.delegate = delegate; AWSCredentials credentials;/*w ww .j av a 2s. c om*/ try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception ex) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", ex); } s3 = new AmazonS3Client(credentials); Region region = Region.getRegion(Regions.EU_WEST_1); s3.setRegion(region); String n = FileSystemUtils.get(env, BUCKET_READ); if (n == null || n.trim().isEmpty()) { n = FileSystemUtils.get(env, BUCKET); } bucketName = Objects.requireNonNull(n, BUCKET + " or " + BUCKET_READ + " is not defined"); }
From source file:org.alfresco.provision.AWSService.java
License:Open Source License
private AWSService(AWSCredentialsProvider credentials, Regions region) { this.ec2 = Region.getRegion(Regions.EU_WEST_1).createClient(AmazonEC2Client.class, credentials, null); this.cloudWatchClient = Region.getRegion(Regions.EU_WEST_1).createClient(AmazonCloudWatchClient.class, credentials, null);// w w w . j a v a 2 s . c o m this.s3 = Region.getRegion(Regions.EU_WEST_1).createClient(AmazonS3Client.class, credentials, null); }
From source file:org.alfresco.provision.CloudWatchMonitor.java
License:Open Source License
public CloudWatchMonitor(String instanceId, String accessKeyId, String secretAccesskey) { AWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyId, secretAccesskey); cloudWatchClient = new AmazonCloudWatchClient(awsCredentials); cloudWatchClient.setRegion(Region.getRegion(Regions.EU_WEST_1)); this.instanceId = instanceId; }