Search in sources :

Example 6 with LambdaContext

use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.

the class S3InternalEventTest method testAppendFilename.

@Test
public void testAppendFilename() {
    TestContext context = new TestContext();
    context.setAwsRequestId("req_id");
    S3InternalEvent ievent = new S3InternalEvent("foo", new LambdaContext(context), 0, "file", "bucket", "v1");
    ievent.setEventObj(null);
    Map<String, String> expected = new HashMap<String, String>(1);
    expected.put(S3InternalEvent.FILENAME_PARTITION, DigestUtils.sha1Hex("file"));
    assertEquals(expected, ievent.getPartitions());
}
Also used : HashMap(java.util.HashMap) TestContext(com.nextdoor.bender.aws.TestContext) LambdaContext(com.nextdoor.bender.LambdaContext) Test(org.junit.Test)

Example 7 with LambdaContext

use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.

the class SNSS3Handler method handler.

@Override
public void handler(SNSEvent event, Context context) throws HandlerException {
    if (!initialized) {
        init(context);
        SNSS3HandlerConfig handlerConfig = (SNSS3HandlerConfig) this.config.getHandlerConfig();
        this.logTrigger = handlerConfig.getLogSnsTrigger();
    }
    this.source = this.sources.get(0);
    this.inputFiles = new ArrayList<String>(0);
    if (this.logTrigger) {
        logger.info("trigger: " + gson.toJson(event));
    }
    for (SNSRecord record : event.getRecords()) {
        /*
       * Parse SNS as a S3 notification
       */
        String json = record.getSNS().getMessage();
        S3EventNotification s3Event = S3EventNotification.parseJson(json);
        /*
       * Validate the S3 file matches the regex
       */
        List<S3EventNotificationRecord> toProcess = new ArrayList<S3EventNotificationRecord>(s3Event.getRecords());
        for (S3EventNotificationRecord s3Record : s3Event.getRecords()) {
            String s3Path = String.format("s3://%s/%s", s3Record.getS3().getBucket().getName(), s3Record.getS3().getObject().getKey());
            try {
                this.source = SourceUtils.getSource(s3Path, this.sources);
            } catch (SourceNotFoundException e) {
                logger.warn("skipping processing " + s3Path);
                toProcess.remove(s3Record);
            }
        }
        if (toProcess.size() == 0) {
            logger.warn("Nothing to process");
            return;
        }
        this.inputFiles.addAll(toProcess.stream().map(m -> {
            return m.getS3().getObject().getKey();
        }).collect(Collectors.toList()));
        this.recordIterator = new S3EventIterator(new LambdaContext(context), toProcess, s3ClientFactory);
        super.process(context);
    }
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) SourceNotFoundException(com.nextdoor.bender.utils.SourceUtils.SourceNotFoundException) SNSRecord(com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord) ArrayList(java.util.ArrayList) LambdaContext(com.nextdoor.bender.LambdaContext)

Example 8 with LambdaContext

use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.

the class DynamodbHandler method handler.

public void handler(DynamodbEvent event, Context context) throws HandlerException {
    if (!initialized) {
        init(context);
    }
    this.recordIterator = new DynamodbEventIterator(new LambdaContext(context), event.getRecords());
    DynamodbStreamRecord firstRecord = event.getRecords().get(0);
    this.source = SourceUtils.getSource(firstRecord.getEventSourceARN(), sources);
    super.process(context);
}
Also used : DynamodbStreamRecord(com.amazonaws.services.lambda.runtime.events.DynamodbEvent.DynamodbStreamRecord) LambdaContext(com.nextdoor.bender.LambdaContext)

Example 9 with LambdaContext

use of com.nextdoor.bender.LambdaContext in project bender by Nextdoor.

the class KinesisHandler method handler.

public void handler(KinesisEvent event, Context context) throws HandlerException {
    if (!initialized) {
        init(context);
    }
    KinesisHandlerConfig handlerConfig = (KinesisHandlerConfig) this.config.getHandlerConfig();
    this.recordIterator = new KinesisEventIterator(new LambdaContext(context), event.getRecords(), handlerConfig.getAddShardIdToPartitions(), handlerConfig.getDecompress(), handlerConfig.getBufferSize());
    /*
     * Get processors based on the source stream ARN
     */
    KinesisEventRecord firstRecord = event.getRecords().get(0);
    this.source = SourceUtils.getSource(firstRecord.getEventSourceARN(), sources);
    super.process(context);
}
Also used : KinesisEventRecord(com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord) LambdaContext(com.nextdoor.bender.LambdaContext)

Example 10 with LambdaContext

use of com.nextdoor.bender.LambdaContext 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(new LambdaContext(context), toProcess, s3ClientFactory);
    super.process(context);
}
Also used : SourceNotFoundException(com.nextdoor.bender.utils.SourceUtils.SourceNotFoundException) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord) ArrayList(java.util.ArrayList) LambdaContext(com.nextdoor.bender.LambdaContext)

Aggregations

LambdaContext (com.nextdoor.bender.LambdaContext)14 TestContext (com.nextdoor.bender.aws.TestContext)10 Test (org.junit.Test)10 InternalEvent (com.nextdoor.bender.InternalEvent)9 JsonElement (com.google.gson.JsonElement)6 GenericJsonEvent (com.nextdoor.bender.deserializer.json.GenericJsonEvent)6 ArraySplitOperation (com.nextdoor.bender.operation.json.array.ArraySplitOperation)6 OperationTest (com.nextdoor.bender.operations.json.OperationTest)6 JsonParser (com.google.gson.JsonParser)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 S3EventNotificationRecord (com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord)2 ContextSubstitution (com.nextdoor.bender.operation.substitution.context.ContextSubstitution)2 DummpyMapEvent (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent)2 SourceNotFoundException (com.nextdoor.bender.utils.SourceUtils.SourceNotFoundException)2 DynamodbStreamRecord (com.amazonaws.services.lambda.runtime.events.DynamodbEvent.DynamodbStreamRecord)1 KinesisEventRecord (com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord)1 SNSRecord (com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord)1 S3EventNotification (com.amazonaws.services.s3.event.S3EventNotification)1 GenericTransportBuffer (com.nextdoor.bender.ipc.generic.GenericTransportBuffer)1