DVA-C02 Question 121
Single answerA developer is building a serverless application using AWS Lambda to process user-uploaded images. The application stores metadata about the images in an Amazon DynamoDB table. The developer notices that the Lambda function execution occasionally exceeds the default time limit of 3 seconds, causing the function to timeout. What is the BEST solution to address the timeout issue?
- A
Increase the Lambda function timeout to a value higher than 3 seconds.
- B
Enable DynamoDB Auto Scaling to handle increased read and write throughput.
- C
Use Amazon SQS to queue requests and process them asynchronously with Lambda.
- D
Move the metadata processing logic to a separate Amazon EC2 instance for better control over execution time.
Show answer and explanation
Correct answer: C
Explanation
When building serverless applications with AWS Lambda, it is important to design for scalability and efficiency. Using Amazon SQS to queue requests allows the application to process requests asynchronously, preventing Lambda from timing out due to long-running tasks. This approach adheres to best practices for serverless applications, ensuring reliable and scalable execution without manual intervention.
- A. Incorrect.
While increasing the Lambda function timeout might temporarily resolve the issue, it does not address the root cause of the delay and is not the best practice for handling long-running processes.
- B. Incorrect.
Enabling DynamoDB Auto Scaling could improve throughput during high traffic, but there is no indication that the issue is related to DynamoDB capacity limits.
- C. Correct.
Using Amazon SQS to queue incoming requests and process them asynchronously with Lambda is the best solution. It decouples the request handling from the processing logic, allowing the Lambda function to process requests without being constrained by execution time.
- D. Incorrect.
Moving metadata processing to an EC2 instance introduces unnecessary complexity, requires additional resource management, and is not aligned with the serverless architecture of the application.