Integrating AWS Lambda with Amazon SNS for Notification Dispatch

Instruction: Discuss how to integrate AWS Lambda with Amazon Simple Notification Service (SNS) for dispatching notifications.

Context: This question assesses the candidate's ability to leverage AWS Lambda in conjunction with Amazon SNS to architect and implement notification dispatch systems.

Updated

Official answer

A Lambda function can publish a message to SNS using its execution-role permission, or subscribe to a standard SNS topic to process notifications. Direct SNS-to-Lambda triggers do not support FIFO topics.

For a notification worker, create the topic and Lambda subscription, then allow that topic to invoke the function through a scoped resource policy. Separately grant the worker permission to use the required delivery service. Parse each SNS record, validate the application payload and derive the recipient from trusted application data.

SNS delivers to Lambda asynchronously. Distinguish a failure to hand the event to Lambda from a handler failure after Lambda accepts it: SNS delivery retries/subscription failure capture and Lambda asynchronous retries/destinations cover different stages. Monitor both. A successful publish or invocation acceptance is not proof that a recipient received a notification.

Use a durable notification ID and a delivery ledger or a provider-supported idempotency key. A crash after sending but before recording success creates an ambiguous outcome; reconcile provider delivery state where possible rather than blindly sending again. Record accepted, sent and failed states separately, with redacted diagnostics and an explicit replay process.

SNS integration, Lambda asynchronous failure handling

Related Questions