पाठ 5 / 32
Synchronous, Asynchronous and Poll-Based Invocation
यह पाठ अभी हिंदी में अनुवादित नहीं है, इसलिए अंग्रेज़ी में दिखाया जा रहा है।
Identify the three invocation models and predict who retries a failed event and where it ends up.
लेखक: Rahul Agarwal · 15 साल से वेब डेवलपर
Who waits, and who retries
There are three ways an event reaches a function, and each fails differently. Synchronous (request/response): the caller, such as API Gateway, waits for the result; if the function fails, the caller sees the error and decides whether to retry. Asynchronous: the caller, such as S3 or EventBridge, hands the event to the platform's internal queue and moves on. On Lambda, failed asynchronous invocations are retried (twice by default) and can then be sent to a dead-letter queue or an on-failure destination. Poll-based (an event source mapping): the platform itself reads from a queue or stream such as SQS or Kinesis and invokes your function with batches. Failure handling depends on the source; with streams, a failing batch can block its shard until it succeeds or the records expire. Knowing which model you are in tells you who retries, how often, and where failed events go.
Invoking the same function two ways
With the AWS CLI, RequestResponse (the default) waits for the result, while Event queues it and returns immediately with HTTP status 202.
# Synchronous: wait for the result and write it to out.json
aws lambda invoke --function-name greet \
--cli-binary-format raw-in-base64-out \
--payload '{"name":"Asha"}' out.json
# Asynchronous: Lambda queues the event and returns at once
aws lambda invoke --function-name greet --invocation-type Event \
--cli-binary-format raw-in-base64-out \
--payload '{"name":"Asha"}' out.jsonPhone call, voicemail and token counter
A synchronous call is a phone call: you wait on the line for the answer. Asynchronous is leaving a voicemail: you hang up, and the other side calls back, maybe retrying if they miss you. Poll-based is a bank token counter: the clerk pulls the next few tokens from the queue whenever ready.
Retries mean duplicates
Because asynchronous and poll-based sources retry automatically, your function will sometimes see the same event twice. Design for it from day one with idempotency (Section 4), instead of discovering it when a customer is charged twice.
त्वरित जाँच: An S3 upload triggers a Lambda function asynchronously and the function throws an error. What happens by default?
- S3 immediately shows an error to the user who uploaded the file
- Lambda retries the invocation, and after the retries it can go to a configured DLQ or destination
- The file upload is automatically rolled back
- Nothing; asynchronous invocations are never retried
Answer
Lambda retries the invocation, and after the retries it can go to a configured DLQ or destination — For asynchronous invocations the platform owns retries. S3 has already finished the upload and does not wait for the function.