S3Handler extends BaseHandler<S3EventNotification> implements Handler<S3EventNotification> { 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)); } List<S3EventNotificationRecord> toProcess = new ArrayList<S3EventNotificationRecord>(event.getRecords()); for (S3EventNotificationRecord record : event.getRecords()) { String s3Path = String.format("s3: 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(new LambdaContext(context), toProcess, s3ClientFactory); super.process(context); }  void handler(S3EventNotification event, Context context); @Override Source getSource(); @Override String getSourceName(); @Override void onException(Exception e); @Override InternalEventIterator<InternalEvent> getInternalEventIterator();  }
@Test public void testSourceRegexFail() 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("foo", false), ctx); assertEquals(0, DummyTransportHelper.BufferedTransporter.output.size()); }
@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()); }