Using RequestStreamHandler for multiple event sources and split on batch failures

0

I have a use case(Scenario 1) where I have a **lambda **which listens to kinesis streams from **DynamoDB **changes, if there is an error while processing any record in the batch of kinesis stream I return the sequence number of the record back so that the batch can be split and since I have defined the max retries, after the retries are exhausted the failed record goes to SQS.

This SQS also we are planning to have it as event source of the same above lambda(Scenario 2). Now the issue is, in case of single event source of KDS(Scenario 1) I was using **RequestHandler **and for batch failure I was returning the sequence number of failed record in the StreamEventResponse. In Scenario 2, I am using RequestStreamHandler since I have multiple event sources(KDS and SQS) and I am writing the sequence number of failed record as below in the OutputStream. However it looks like Lambda is not treating it as failure and not performing any retries. Is there a way to achieve scenario 2 using RequestStreamHandler where I can return the seq number for lambda to retry?

**Scenario 2 where KDS and SQS are the event sources for the same lambda **

public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException
{

      final byte[] byteArray= IOUtils.toByteArray(input);
      String request= new String(byteArray, StandardCharSets.UTF_8);
      KinesisEvent kinesisEvent=new ObjectMapper.readValue(request,KinesisEvent.class);
      String seqNo= kinesisEvent.getRecords().get(0).getKinesis().getSequenceNumber();
      List<StreamEventResponse.BatchItemFailure> batchItemFailures = new ArrayList();
      batchItemFailures.add(new StreamEventResponse.BatchItemFailure(seqNo));
      byte[] failures = SerializationUtils.serialize(new StreamEventResponse(batchItemFailures));

      output.write(failures); 

}
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