DVA-C02 Question 31
Single answerYou are developing a serverless application using AWS Lambda and Amazon SQS. A business requirement specifies that when a message is sent to the SQS queue, it must be processed by the Lambda function immediately to update a database. Which integration approach should you use, and why?
- A
Synchronous invocation of the Lambda function using an API Gateway trigger.
- B
Asynchronous invocation of the Lambda function using an SQS queue as the event source.
- C
Synchronous invocation of the Lambda function with SQS using AWS SDK.
- D
Asynchronous invocation of the Lambda function by polling SQS messages from the queue.
Show answer and explanation
Correct answer: B
Explanation
The correct answer is to use asynchronous invocation of the Lambda function with SQS as the event source. This integration pattern allows Lambda to automatically poll the SQS queue, ensuring that messages are processed immediately and efficiently. It eliminates the need for manual polling or additional infrastructure, aligning with the serverless model and reducing operational complexity.
- A. Incorrect.
Synchronous invocation with API Gateway is not relevant in this scenario because the requirement involves processing messages from SQS, not an API Gateway trigger.
- B. Correct.
Asynchronous invocation of the Lambda function with SQS as the event source is the correct approach because it allows Lambda to automatically poll the SQS queue and process messages without requiring manual intervention, ensuring near real-time processing.
- C. Incorrect.
Synchronous invocation with SQS using AWS SDK is not suitable for this scenario because it would require a custom implementation to continually poll the queue, which is not efficient or scalable.
- D. Incorrect.
Polling SQS messages manually for asynchronous invocation is not the best practice because AWS Lambda can natively integrate with SQS as an event source, simplifying the implementation and reducing operational overhead.