Kinesis Delivery Stream: PutRecordBatchRequest throws ValidationException

0

In my Java 17 Lambda function, I am trying to send record batches to a Kinesis Firehose Delivery Stream as follows:

List<Record> recordList = new ArrayList<>();

for (int i = 0; i < 2; i++) {
    org.json.JSONObject json = new JSONObject();

    json.put("key1", "value1");
    json.put("key2", "value2");

    byte[] data = compressMessage((json + "\r\n").getBytes(StandardCharsets.UTF_8));

    recordList.add(new Record().withData(ByteBuffer.wrap(data)));
}

PutRecordBatchRequest request = new PutRecordBatchRequest()
	.withDeliveryStreamName(deliveryStreamName)
	.withRecords(recordList);

List<PutRecordBatchResponseEntry> results = firehoseClient.putRecordBatch(request).getRequestResponses();

However, I always get the following error:

AmazonServiceException: Unable to unmarshall exception response with the unmarshallers provided (Service: AmazonKinesisFirehose; Status Code: 400; Error Code: ValidationException)

When I test my Delivery Stream with sample data in the Kinesis console, it works, so I don't understand what I am doing wrong.

Can somebody please help me?

No Answers

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