List of usage examples for com.amazonaws.services.s3.event S3EventNotification S3EventNotification
@JsonCreator public S3EventNotification(@JsonProperty(value = "Records") List<S3EventNotificationRecord> records)
From source file:com.nextdoor.bender.Bender.java
License:Apache License
protected static void invokeS3Handler(String source_file) throws HandlerException { /*//w ww. j a v a 2 s . co m * 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(); }
From source file:com.nextdoor.bender.S3SnsNotifier.java
License:Apache License
public static S3EventNotification getS3Notification(String key, String bucket, long size) { S3ObjectEntity objEntity = new S3ObjectEntity(key, size, null, null); S3BucketEntity bucketEntity = new S3BucketEntity(bucket, null, null); S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null); String timestamp = formatter.print(System.currentTimeMillis()); S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null, timestamp, null, null, null, entity, null);/*from www . ja va 2s . c o m*/ List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(1); notifications.add(rec); return new S3EventNotification(notifications); }