Java Code Examples for com.amazonaws.services.lambda.runtime.events.KinesisEvent#KinesisEventRecord

The following examples show how to use com.amazonaws.services.lambda.runtime.events.KinesisEvent#KinesisEventRecord . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KinesisToFirehose.java    From aws-big-data-blog with Apache License 2.0 6 votes vote down vote up
public void kinesisHandler(KinesisEvent event, Context context){
    logger = context.getLogger();
    setup();
    for(KinesisEvent.KinesisEventRecord rec : event.getRecords()) {
        logger.log("Got message ");
        String msg = new String(rec.getKinesis().getData().array())+"\n";
        Record deliveryStreamRecord = new Record().withData(ByteBuffer.wrap(msg.getBytes()));

        PutRecordRequest putRecordRequest = new PutRecordRequest()
                .withDeliveryStreamName(deliveryStreamName)
                .withRecord(deliveryStreamRecord);

        logger.log("Putting message");
        firehoseClient.putRecord(putRecordRequest);
        logger.log("Successful Put");
    }
}
 
Example 2
Source File: SpringBootKinesisEventHandlerTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private static KinesisEvent asAggregatedKinesisEvent(List<?> payloads) {
	RecordAggregator aggregator = new RecordAggregator();

	payloads.stream().map(SpringBootKinesisEventHandlerTests::asJsonByteBuffer)
			.forEach(buffer -> {
				try {
					aggregator.addUserRecord("fakePartitionKey", buffer.array());
				}
				catch (Exception e) {
					fail("Creating aggregated record failed");
				}
			});

	AggRecord aggRecord = aggregator.clearAndGet();

	KinesisEvent.Record record = new KinesisEvent.Record();
	record.setData(ByteBuffer.wrap(aggRecord.toRecordBytes()));

	KinesisEvent.KinesisEventRecord wrappingRecord = new KinesisEvent.KinesisEventRecord();
	wrappingRecord.setKinesis(record);
	wrappingRecord.setEventVersion("1.0");

	KinesisEvent event = new KinesisEvent();
	event.setRecords(singletonList(wrappingRecord));

	return event;
}
 
Example 3
Source File: SpringBootKinesisEventHandler.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
private List<E> deserializePayloads(List<KinesisEvent.KinesisEventRecord> records) {
	return RecordDeaggregator.deaggregate(records).stream()
			.map(this::deserializeUserRecord).collect(toList());
}
 
Example 4
Source File: SpringBootKinesisEventHandlerTests.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
private static KinesisEvent asKinesisEvent(List<Object> payloads) {
	KinesisEvent kinesisEvent = new KinesisEvent();

	List<KinesisEvent.KinesisEventRecord> kinesisEventRecords = new ArrayList<>();

	for (Object payload : payloads) {
		KinesisEvent.Record record = new KinesisEvent.Record();
		record.setData(asJsonByteBuffer(payload));

		KinesisEvent.KinesisEventRecord kinesisEventRecord = new KinesisEvent.KinesisEventRecord();
		kinesisEventRecord.setKinesis(record);

		kinesisEventRecords.add(kinesisEventRecord);
	}

	kinesisEvent.setRecords(kinesisEventRecords);

	return kinesisEvent;
}