Seeing that some event sources send multiple event records in a batch1, and that a single Lambda may be made available to both to a multiple-record event sources (e.g. SQS, SES) and a single request event source (e.g. API Gateway), does anyone have any examples of handling both a single API request and multiple record SQS or other source events with the same Lambda?
This is a little more involved than limiting the batch size, since the event objects from different services don't always have a list of records, e.g. API Gateway sends a single request object event payload, rather than a list of records.
I have been able to figure out how to parse the events based on the eventSource key; however, I don't understand how Lambda responds to multiple-record events.
Is there one invocation record per event record, or is there a single invocation record, i.e. does the Lambda code run once per batch or multiple times?
Is my Lambda code responsible for forming the invocation record(s), or just the response payload?
How do I form my response payload(s) from a multiple-record event batch?
Do I respond to each record individually and build up a single payload with the responses for each individual record, then return the aggregate payload?
On one hand, I may just want the Lambda to do something and not return anything, such as an asynchronous invocation that isn't expecting a response. On the other hand, a synchronous API gateway request would expect a response, or another asynchronous invocation may expect responses to be published to another queue.
I am making the assumption that each record in a multiple-record SQS Queue event batch is equivalent to a single request event from API Gateway. Is this incorrect?