DVA-C02 Question 32
Single answerA developer is building a serverless application on AWS where user data is uploaded via an API Gateway and processed by a Lambda function. The processing involves time-consuming image analysis that can take up to 10 minutes per request. The developer needs to ensure that the API Gateway immediately responds to the user without waiting for the processing to complete. Which approach should the developer use?
- A
Configure the API Gateway to use a synchronous invocation of the Lambda function.
- B
Use an asynchronous invocation of the Lambda function with API Gateway.
- C
Configure a Step Function to handle the processing task directly through API Gateway.
- D
Write the user data to an Amazon SQS queue from the API Gateway, and trigger the Lambda function from the queue.
Show answer and explanation
Correct answer: B
Explanation
Asynchronous invocation of Lambda is the best choice here because it allows the API Gateway to respond immediately without waiting for the image processing to complete. This approach simplifies the architecture and ensures a scalable and efficient solution. While other options may achieve similar results, they either add unnecessary complexity or fail to address the requirement for immediate response.
- A. Incorrect.
Incorrect. Synchronous invocation waits for the Lambda function to complete execution before returning a response, which is not suitable for time-consuming tasks.
- B. Correct.
Correct. Asynchronous invocation of the Lambda function allows the API Gateway to immediately respond to the user while the processing task runs in the background.
- C. Incorrect.
Incorrect. Step Functions are not invoked directly by API Gateway. They require additional configuration and are not the most efficient solution for this specific scenario.
- D. Incorrect.
Incorrect. Using Amazon SQS is a valid asynchronous pattern, but it adds unnecessary complexity in this case since Lambda can be directly invoked asynchronously by API Gateway.