Q60 — AWS SAA-C03 Ch.15
Question 60 of 100 | ← Chapter 15
Q1160. A company has a serverless application that uses an AWS Lambda function behind an Amazon API Gateway REST API to store data in an Amazon DynamoDB table. Queries to the database can be time- consuming. The API clients do not need to receive the results of the queries.A solutions architect wants to decrease the response time of the API and avoid timeout issues.Which solution will meet these requirements?
- A. Create an Amazon Kinesis data stream. Configure the REST API endpoint to use the Kinesis data stream as a destination. Configure the Lambda function to read records from the data stream.
- B. Create an Amazon Simple Notification Service(Amazon SNS) topic. Configure the REST API endpoint to use the SNS topic as a destination. Configure the Lambda function to subscribe to the SNS topic.
- C. Create an Application Load Balancer (ALB). Configure the ALB as the destination of the REST API. Set the Lambda function as the target of the ALB. Configure Application Auto Scaling to scale Lambda provisioned concurrency based on to the application latency.
- D. Create an Amazon Simple Queue Service (Amazon SQS) queue. Configure the REST API endpoint to use the SQS queue as a direct destination. Configure the Lambda function to read from the SQS queue. ✓
Correct Answer: D. Create an Amazon Simple Queue Service (Amazon SQS) queue. Configure the REST API endpoint to use the SQS queue as a direct destination. Configure the Lambda function to read from the SQS queue.
Explanation
To meet the requirements of decreasing the response time of the API and avoiding timeout issues for a serverless application where API clients do not need immediate query results, the best solution is to decouple the API response from the database query execution. This can be achieved by using asynchronous processing with a queue.Key Requirements:Decrease API response time (clients should not wait for slow queries). Avoid timeout issues (Lambda has a maximum execution time, and slow queries may exceed it). API clients do not need results (so the API can return immediately after enqueuing the request).Option Analysis:A. Create an Amazon Kinesis data stream. Configure the REST API endpoint to use the Kinesis data stream as a destination. Configure the Lambda function to read records from the data stream. Kinesis is for real-time streaming data (e.g., log ingestion, IoT telemetry). It is not the best fit for simple asynchronous task queuing (overkill for this use case). Not ideal for decoupling API requests from database queries. B. Create an Amazon Simple Notification Service (Amazon SNS) topic. Configure the REST API endpoint to use the SNS topic as a destination. Configure the Lambda function to subscribe to the SNS topic. SNS is for publish/subscribe messaging (e.g., notifications, alerts). While it can trigger a Lambda function, it is not a queue (no guarantee of order or exactly-once processing).Not suitable for reliable asynchronous task processing.C. Create an Application Load Balancer (ALB). Configure the ALB as the destination of the REST API. Set the Lambda function as the target of the ALB. Configure Application Auto Scaling to scale Lambda provisioned concurrency based on the application latency.ALB + Lambda is for HTTP-based workloads but does not solve the timeout issue (Lambda still has to execute the query synchronously).Provisioned concurrency helps with cold starts but does not address slow database queries.Not the best solution for asynchronous processing.D. Create an Amazon Simple Queue Service (Amazon SQS) queue. Configure the REST API endpoint to use the SQS queue as a direct destination. Configure the Lambda function to read from the SQS queue. SQS is a fully managed message queue that decouples the API from the database query. The API can return immediately after enqueuing the request (no waiting for the query). The Lambda function can process the message asynchronously, avoiding timeouts.Best fit for the requirements.Correct Answer:D. Create an Amazon Simple Queue Service (Amazon SQS) queue. Configure the REST API endpoint to use the SQS queue as a direct destination. Configure the Lambda function to read from the SQS queue.This solution provides:Decoupled processing (API returns immediately, Lambda processes later). Avoids timeout issues (Lambda does not block on slow queries). Reliable asynchronous task handling (SQS ensures messages are processed).Final Answer:D. Create an Amazon Simple Queue Service (Amazon SQS) queue. Configure the REST API endpoint to use the SQS queue as a direct destination. Configure the Lambda function to read from the SQS queue. The solution that will meet the requirements of decreasing the response time of the API and avoiding timeout issues is:D. Create an Amazon Simple Queue Service (Amazon SQS) queue. Configure the REST API endpoint to use the SQS queue as a direct destination. Configure the Lambda function to read from the SQS queue.Amazon SQS: This service allows for asynchronous processing of requests. By placing requests in a queue, the API can respond immediately to clients without waiting for the Lambda function to complete the DynamoDB query.Decoupling: By decoupling the API request from the Lambda function's execution, you eliminate potential timeout issues that can occur when the function takes too long to process a query. Improved Response Time: Clients receive a quick acknowledgment that their request has been received, while the processing of the query happens independently, enhancing the overall user experience.This approach effectively addresses the performance concerns while ensuring that the API remains responsive.