Java Code Examples for com.amazonaws.services.s3.AmazonS3URI#getBucket()
The following examples show how to use
com.amazonaws.services.s3.AmazonS3URI#getBucket() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoIpOperationFactory.java From bender with Apache License 2.0 | 6 votes |
@Override public void setConf(AbstractConfig config) { this.config = (GeoIpOperationConfig) config; AmazonS3Client client = this.s3Factory.newInstance(); AmazonS3URI uri = new AmazonS3URI(this.config.getGeoLiteDb()); GetObjectRequest req = new GetObjectRequest(uri.getBucket(), uri.getKey()); S3Object obj = client.getObject(req); try { this.databaseReader = new DatabaseReader.Builder(obj.getObjectContent()).withCache(new CHMCache()).build(); } catch (IOException e) { throw new ConfigurationException("Unable to read " + this.config.getGeoLiteDb(), e); } }
Example 2
Source File: S3S3Copier.java From circus-train with Apache License 2.0 | 5 votes |
private void initialiseCopyJobsFromListing( AmazonS3URI sourceS3Uri, final AmazonS3URI targetS3Uri, ListObjectsRequest request, ObjectListing listing) { LOG .debug("Found objects to copy {}, for request {}/{}", listing.getObjectSummaries(), request.getBucketName(), request.getPrefix()); List<S3ObjectSummary> objectSummaries = listing.getObjectSummaries(); for (final S3ObjectSummary s3ObjectSummary : objectSummaries) { totalBytesToReplicate += s3ObjectSummary.getSize(); String fileName = StringUtils.removeStart(s3ObjectSummary.getKey(), sourceS3Uri.getKey()); final String targetKey = Strings.nullToEmpty(targetS3Uri.getKey()) + fileName; CopyObjectRequest copyObjectRequest = new CopyObjectRequest(s3ObjectSummary.getBucketName(), s3ObjectSummary.getKey(), targetS3Uri.getBucket(), targetKey); if (s3s3CopierOptions.getCannedAcl() != null) { copyObjectRequest.withCannedAccessControlList(s3s3CopierOptions.getCannedAcl()); } applyObjectMetadata(copyObjectRequest); TransferStateChangeListener stateChangeListener = new BytesTransferStateChangeListener(s3ObjectSummary, targetS3Uri, targetKey); copyJobRequests.add(new CopyJobRequest(copyObjectRequest, stateChangeListener)); } }
Example 3
Source File: S3DataManipulator.java From circus-train with Apache License 2.0 | 5 votes |
@Override public boolean delete(String path) { log.info("Deleting all data at location: {}", path); AmazonS3URI uri = toAmazonS3URI(URI.create(path)); String bucket = uri.getBucket(); List<KeyVersion> keysToDelete = getKeysToDelete(bucket, uri.getKey()); log.debug("Deleting keys: {}", keysToDelete.stream().map(k -> k.getKey()).collect(Collectors.toList())); DeleteObjectsResult result = s3Client.deleteObjects(new DeleteObjectsRequest(bucket).withKeys(keysToDelete)); return successfulDeletion(result, keysToDelete.size()); }
Example 4
Source File: BucketKey.java From s3-inventory-usage-examples with Apache License 2.0 | 5 votes |
public BucketKey(String inputFilePath, String outputFilePath){ AmazonS3URI srcURI = new AmazonS3URI(inputFilePath); AmazonS3URI destURI = new AmazonS3URI(outputFilePath); this.srcBucket = srcURI.getBucket(); this.srcKey = srcURI.getKey(); this.destBucket = destURI.getBucket(); this.destPrefix = destURI.getKey(); }
Example 5
Source File: Bender.java From bender with Apache License 2.0 | 4 votes |
protected static void invokeS3Handler(String source_file) throws HandlerException { /* * https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html * https://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html */ String awsRegion = "us-east-1"; String eventName = "s3:ObjectCreated:Put"; String eventSource = "aws:s3"; String eventVersion = "2.0"; String s3ConfigurationId = "cli-id"; String s3SchemaVersion = "1.0"; S3BucketEntity s3BucketEntity = null; S3ObjectEntity s3ObjectEntity = null; /* * Make sure the URL was submitted properly * * Split the s3://bucket/object path into an S3BucketEntity and S3ObjectEntity object */ try { AmazonS3URI s3URI = new AmazonS3URI(source_file); s3BucketEntity = new S3BucketEntity(s3URI.getBucket(), null, null); s3ObjectEntity = new S3ObjectEntity(s3URI.getKey(), 1L, null, null); } catch (IllegalArgumentException e) { logger.error( "Invalid source_file URL supplied (" + source_file + "): " + e); System.exit(1); } /* * Override the AWS Region if its supplied */ if (System.getenv("AWS_REGION") != null) { awsRegion = System.getenv("AWS_REGION"); } /* * Set the arrival timestamp as the function run time. */ DateTime eventTime = new DateTime().toDateTime(); /* * Generate our context/handler objects.. we'll be populating them shortly. */ TestContext ctx = getContext(); S3Handler handler = new S3Handler(); /* * Create a S3EventNotification event */ S3Entity s3Entity = new S3Entity(s3ConfigurationId, s3BucketEntity, s3ObjectEntity, s3SchemaVersion); S3EventNotificationRecord rec = new S3EventNotificationRecord(awsRegion, eventName, eventSource, eventTime.toString(), eventVersion, null, null, s3Entity, null); List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(2); notifications.add(rec); S3EventNotification s3event = new S3EventNotification(notifications); /* * Invoke handler */ handler.handler(s3event, ctx); handler.shutdown(); }
Example 6
Source File: S3ClientFactory.java From genie with Apache License 2.0 | 4 votes |
/** * Get an {@link AmazonS3} client instance appropriate for the given {@link AmazonS3URI}. * * @param s3URI The URI of the S3 resource this client is expected to access. * @return A S3 client instance which should be used to access the S3 resource */ public AmazonS3 getClient(final AmazonS3URI s3URI) { final String bucketName = s3URI.getBucket(); final S3ClientKey s3ClientKey; /* * The purpose of the dual maps is to make sure we don't create an unnecessary number of S3 clients. * If we made the client cache just bucketName -> client directly we'd have no way to make know if an already * created instance for another bucket could be re-used for this bucket since it could be same region/role * combination. This way we first map the bucket name to a key of role/region and then use that key * to find a re-usable client for those dimensions. */ s3ClientKey = this.bucketToClientKey.computeIfAbsent( bucketName, key -> { // We've never seen this bucket before. Calculate the key. /* * Region Resolution rules: * 1. Is it part of the S3 URI already? Use that * 2. Is it part of the properties passed in by admin/user Use that * 3. Fall back to whatever the default is for this process */ final Regions bucketRegion; final String uriBucketRegion = s3URI.getRegion(); if (StringUtils.isNotBlank(uriBucketRegion)) { bucketRegion = Regions.fromName(uriBucketRegion); } else { final String propertyBucketRegion = this.bucketProperties.containsKey(key) ? this.bucketProperties.get(key).getRegion().orElse(null) : null; if (StringUtils.isNotBlank(propertyBucketRegion)) { bucketRegion = Regions.fromName(propertyBucketRegion); } else { bucketRegion = this.defaultRegion; } } // Anything special in the bucket we need to reference final String roleARN = this.bucketProperties.containsKey(key) ? this.bucketProperties.get(key).getRoleARN().orElse(null) : null; return new S3ClientKey(bucketRegion, roleARN); } ); return this.clientCache.computeIfAbsent(s3ClientKey, this::buildS3Client); }