Lambda handler functions
Overview
Backend logic is done by Lambda functions, Lambda functions can be triggered from multiple services, we split our code into two parts, a handler function which is the initial entry point into the Lamdba, it receives the request and performs request method specific handling, it then invokes the main logic of the Lambda, which is request method agnostic, allowing it to be invoked by any request method.
CorrelationId and Logger instances
Our middleware has CorrelationId and Logger classes which manage the passing of correlation ids between services and output these ids to logs. If the request method invokes the lambda with a single workflow/message these are placed into global instances, but if the request service handles batches of messages each message will carry its own instance.
In order for our main logic to be able to handle single or batch requests we cannot assume the global instances are to be used, to allow for this we standardize that main logic always receives correlationIds and logger parameters when invoked, the handler function sets which are used. Because these will always be present standardize them as the first two parameters.