DVA-C02 Question 20
Single answerYou are developing a web application that uses an Amazon API Gateway to trigger AWS Lambda functions. The API Gateway endpoints are stateless, but the Lambda function requires session-specific data to process user requests. Which of the following is the best approach to handle this requirement?
- A
Store session-specific data in Amazon DynamoDB and pass a session ID to the Lambda function.
- B
Use an Elastic Load Balancer to maintain session information and forward it to the Lambda function.
- C
Store session-specific data in the API Gateway's stateful context and retrieve it within the Lambda function.
- D
Pass all session-specific data directly in the API request payload to the Lambda function.
Show answer and explanation
Correct answer: A
Explanation
Stateless services like API Gateway and Lambda do not retain information between requests. To handle session-specific data, it is necessary to use external storage solutions like Amazon DynamoDB to maintain state outside the compute environment. By passing a session ID in the request, the Lambda function can retrieve only the required data without violating the stateless nature of the services.
- A. Correct.
This is the correct option. Amazon DynamoDB is well-suited for storing session-specific data due to its scalability and low-latency performance. Passing a session ID allows the Lambda function to retrieve the necessary data without storing state locally.
- B. Incorrect.
Elastic Load Balancers are used for distributing traffic and do not directly manage session data for stateless services like API Gateway or Lambda.
- C. Incorrect.
API Gateway is inherently stateless and does not support storing session data. This makes this option invalid.
- D. Incorrect.
While passing session-specific data directly in the payload is possible, it is not optimal for performance or security, especially when data grows in size or contains sensitive information.