use of com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord in project bender by Nextdoor.
the class TestUtils method createEvent.
public static KinesisEvent createEvent(Class clazz, String resource) throws UnsupportedEncodingException, IOException {
/*
* Create a kinesis record from a sample JSON file
*/
String json = IOUtils.toString(new InputStreamReader(clazz.getResourceAsStream(resource), "UTF-8"));
Date approximateArrivalTimestamp = new Date();
approximateArrivalTimestamp.setTime(1478737790000l);
Record rec = new Record();
rec.withPartitionKey("1").withSequenceNumber("2").withData(ByteBuffer.wrap(json.getBytes())).withApproximateArrivalTimestamp(approximateArrivalTimestamp);
/*
* Create a KinesisEventRecord and add single Record
*/
KinesisEventRecord krecord = new KinesisEventRecord();
krecord.setKinesis(rec);
krecord.setEventSourceARN("arn:aws:kinesis:us-east-1:1234:stream/test-events-stream");
krecord.setEventID("shardId-000000000000:1234");
/*
* Add single KinesisEventRecord to a KinesisEvent
*/
KinesisEvent kevent = new KinesisEvent();
List<KinesisEventRecord> events = new ArrayList<KinesisEventRecord>(1);
events.add(krecord);
kevent.setRecords(events);
return kevent;
}
use of com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord 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(context, event.getRecords(), handlerConfig.getAddShardIdToPartitions());
/*
* Get processors based on the source stream ARN
*/
KinesisEventRecord firstRecord = event.getRecords().get(0);
this.source = SourceUtils.getSource(firstRecord.getEventSourceARN(), sources);
super.process(context);
}
Aggregations