use of com.nextdoor.bender.handler.s3.S3Handler in project bender by Nextdoor.
the class Bender method invokeS3Handler.
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();
}
Aggregations