By using AWS re:Post, you agree to the Terms of Use

Help processing Kinessis Records with KCL and Java


How am I supposed to process the actual record in Java using KCL?

I'm following the guidance provided, I can connect to the data stream, I can get the number of records available, however what the example doesn't show is how to actually get the record (Json string). From the example I can see that I can use to get the record's data, it comes as a read only ByteBuffer, I can convert this to string by using StandardCharsets.US_ASCII.decode(, however the resulting string is definitely encoded, I have tried doing Base64 decoding but I get error java.lang.IllegalArgumentException: Illegal base64 character 3f. So what is the simplest way to get the payload? Below is my processRecords method:

public void processRecords(ProcessRecordsInput processRecordsInput) {
    try {
        System.out.println("Processing " + processRecordsInput.records().size() + " record(s)");
        processRecordsInput.records().forEach((r) -> {
            try {
                Decoder dec = Base64.getDecoder();
                String myString = StandardCharsets.US_ASCII.decode(;
                byte[] bt = dec.decode(myString);
            } catch (Exception e) {
    } catch (Throwable t) {
        System.out.println("Caught throwable while processing records. Aborting.");
    } finally {

From here I can get myString but when I get to bt I get the exception shown. I have not found a single resource explaining how to get the record. I post the record to kinesis using aws kinesis put-record --stream-name testStream --partition-key 1 --data {"somedata":"This Data"}

1 Answers
Accepted Answer

The problem was in the producer which was not producing the correct data, using String myString = StandardCharsets.US_ASCII.decode(; would give you the String as expected.

answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions