This project is designed for a hands on exploration of Lambda Error Handling when using the Kinesis Event Source. At this time the key elements for this project include:
- The s1_producer_errs/producer.py is a utility script which populates messages into Kinesis
- The s1_consumer/consumer.py is a python script which receives data from the Kinesis Event Source. Within the script there are various data checks to fire off errors.
- You cannot use Dead Letter Queues from the Asynchronous Configuration as the Kinesis Data Source Event Source does not permit the Lambda Dead Letter Queue. To setup a Dead Letter queue it is necessary to have your program automatically direct messages for retry.
- the raise exception operation in python is necessary to dispay errors in the Lambda functions monitor error chart. Play around with the raise of exceptions to understand
After you have cloned this repository and reviewed the template.yml (AWS SAM file) and the python source code, then you are ready to deploy the infrastructure to build the infrastructure and populate the Kinesis data stream.
sam build & sam deploy --guided
At this point check out the Lambda Functions and confirm that the functions KdsErrProducer and KdsConsumer are present. Also, from the Kinesis Data Streams list confirm that there is a new stream which starts with the same name as the stack.
Set the number of rows to push into the Kinesis stream within the source code for s1_producer_errs/producer.py. The default is 100 rows, which should provide enough data to explore different error situations.
python producerInvoker.py
You will see the Kinesis put response as well as the row count display as rows are added. When the program is done, you will see the message 'Finished' in the console.
Go into Lambda -> Functions and click on the KdsConsumer function. From there click on Monitor. If all successful you will see various metrics. We are interested in the "Error Count and success rate" monitoring pane, if all is successful at the end of the first producerInvoker you should see errors displayed here.
Play around with various configurations in the template to experiment with different options.
Next steps in the project are:
- Add DLQ output from the consumer.py
- How long do the Lambda functions take to invoke?
- Verify duplicate impact