How To Design Lambda functions?
The following are the general design principles for designing AWS Lambda functions.
Single Purpose
Your function should be concise, short, simple, single-purpose, and follows Single-Responsibility-Principle.
No monolithic Lambda Functions
Your function should not have internal branching logic, which makes them monolithic, and harder to change, and maintain.
Share nothing
Function runtime environment and underlying infrastructure are short-lived, therefore local resources such as temporary storage are not guaranteed.
The state can be manipulated within a state machine execution lifecycle.
Persistent storage is preferred for highly durable requirements.
Design for failures and duplicates
Operations triggered from requests/events must be idempotent as failures can occur and a given request/event can be delivered more than once. Include appropriate retries for downstream calls.