AWS Certified Developer – Associate / Question #868 of 557

Question #868

A company has developed a serverless application for its online booking system. The application uses Amazon API Gateway for a REST API that triggers an AWS Lambda function. This function processes booking data, stores it in Amazon DynamoDB, and interacts with a third-party payment gateway API. The Lambda function returns an HTTP 200 status with no body once the payment is processed. During high traffic, the payment gateway API becomes overwhelmed, leading to errors. The company needs a solution that prevents exceeding the payment gateway's rate limits.

Which solution meets these requirements?

A

Modify the API Gateway to write requests directly into DynamoDB. Use a DynamoDB stream to invoke the Lambda function with reserved concurrency set to the payment gateway's limit. Process payments via the stream.

B

Configure API Gateway to send requests to an Amazon Kinesis Data Stream. Set the number of shards to match the payment gateway's threshold. Use Lambda with parallelization per shard to process records and interact with the payment API.

C

Set up API Gateway to write requests into an Amazon SQS queue. Configure the Lambda function with reserved concurrency equal to the payment gateway's limit. Process messages from the queue with this Lambda.

D

Direct API Gateway requests to an Amazon SNS topic. Use a Lambda function with provisioned concurrency set to the payment gateway's threshold. Subscribe Lambda to the SNS topic for message processing.

Explanation

Option C is correct because:
- Amazon SQS acts as a buffer, decoupling API Gateway from the payment processing. API Gateway writes requests directly to SQS, preventing overwhelming the payment gateway during traffic spikes.
- Reserved Concurrency on the Lambda function limits the number of concurrent executions to match the payment gateway's rate limit. This ensures only a controlled number of requests are processed simultaneously.

Why other options are incorrect:
- A: DynamoDB streams introduce async processing, altering the original synchronous flow where Lambda returns 200 after payment. This could delay payment processing and complicate error handling.
- B: Kinesis requires shard management and focuses on ordered data streams, which is overkill for simple rate limiting. Shards don't directly map to concurrency limits.
- D: SNS with provisioned concurrency does not limit Lambda concurrency; it only pre-initializes instances, failing to prevent exceeding the payment gateway's rate limits.

Key Points: Use SQS for buffering and Lambda reserved concurrency to enforce rate limits. Avoid solutions that alter the flow (A), add complexity (B), or lack concurrency control (D).

Answer

The correct answer is: C