Soru

Zorluk: OrtaServerless Development with AWS Lambda

A developer is building a serverless application where an Amazon S3 bucket triggers an AWS Lambda function asynchronously when new files are uploaded. The Lambda function processes each file and performs data extraction. Under heavy load, some files fail to process. The developer wants to ensure that any failed event payload is automatically sent to an Amazon SQS queue for manual analysis, rather than being discarded. Which of the following is the AWS-recommended method to achieve this?

  1. Configure an On-Failure Lambda Destination for the function and specify the SQS queue as the destination.Cevap
  2. B
    Implement a try-catch block inside the Lambda function handler to capture errors and use the AWS SDK to write the payload to the SQS queue.
  3. C
    Modify the trust policy of the Lambda execution role to allow the SQS service to write directly to the queue when the function execution fails.
  4. D
    Increase the visibility timeout of the SQS queue to be at least six times the timeout of the Lambda function to ensure failed messages are retried.

Cevap

Configure an On-Failure Lambda Destination for the function and specify the SQS queue as the destination.
The correct approach is to configure an On-Failure Lambda Destination. For asynchronous invocations, Lambda can route execution records to external services like SQS on failure. This handles all execution errors, including application-level errors, timeouts, and out-of-memory crashes.

Adım Adım Çözüm

1
Identify the invocation model of the Lambda function.
The function is triggered by S3, which executes Lambda asynchronously.
Asynchronous invocations support Lambda Destinations for routing successful or failed execution results.
2
Select the appropriate target for capturing failed executions.
Choose the SQS queue as the destination for the On-Failure condition.
An On-Failure destination automatically intercepts and forwards the event payload when the Lambda execution fails, including timeouts.
3
Configure the necessary IAM permissions.
Grant the Lambda execution role permission to write to the SQS queue.
Lambda requires the `sqs:SendMessage` permission to deliver the failure payload to the destination queue.

Anahtar Kavram

AWS Lambda Asynchronous Invocation Destinations
Bu soruyu puanla