use of com.amazonaws.services.s3.event.S3EventNotification in project bender by Nextdoor.
the class S3HandlerTest method testSourceRegex.
@Test
public void testSourceRegex() throws Throwable {
BaseHandler.CONFIG_FILE = "/com/nextdoor/bender/handler/config_s3_source.json";
TestContext ctx = new TestContext();
ctx.setFunctionName("unittest");
ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");
BaseHandler<S3EventNotification> handler = (BaseHandler) getHandler();
handler.init(ctx);
handler.handler(getTestEvent(), ctx);
assertEquals(1, DummyTransportHelper.BufferedTransporter.output.size());
}
use of com.amazonaws.services.s3.event.S3EventNotification in project bender by Nextdoor.
the class S3HandlerTest method getTestEvent.
private S3EventNotification getTestEvent(String bucket, boolean doPut) throws Exception {
/*
* Upload a test resoruce to the mock S3
*/
if (doPut) {
String payload = IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream("basic_input.log"), "UTF-8"));
this.client.putObject(bucket, "basic_input.log", payload);
}
/*
* Create a S3EventNotification event
*/
S3ObjectEntity objEntity = new S3ObjectEntity("basic_input.log", 1L, null, null);
S3BucketEntity bucketEntity = new S3BucketEntity(bucket, null, null);
S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null, "1970-01-01T00:00:00.000Z", null, null, null, entity, null);
List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(2);
notifications.add(rec);
return new S3EventNotification(notifications);
}
use of com.amazonaws.services.s3.event.S3EventNotification in project bender by Nextdoor.
the class S3Handler method handler.
public void handler(S3EventNotification event, Context context) throws HandlerException {
if (!initialized) {
init(context);
S3HandlerConfig handlerConfig = (S3HandlerConfig) this.config.getHandlerConfig();
this.logTrigger = handlerConfig.getLogS3Trigger();
}
if (this.logTrigger) {
logger.info("trigger: " + gson.toJson(event));
}
/*
* Validate the S3 file matches the regex
*/
List<S3EventNotificationRecord> toProcess = new ArrayList<S3EventNotificationRecord>(event.getRecords());
for (S3EventNotificationRecord record : event.getRecords()) {
String s3Path = String.format("s3://%s/%s", record.getS3().getBucket().getName(), record.getS3().getObject().getKey());
try {
this.source = SourceUtils.getSource(s3Path, this.sources);
} catch (SourceNotFoundException e) {
logger.warn("Skipping processing " + s3Path);
toProcess.remove(record);
}
}
if (toProcess.size() == 0) {
logger.warn("Nothing to process");
return;
}
this.recordIterator = new S3EventIterator(context, toProcess, s3ClientFactory);
super.process(context);
}
Aggregations