DVA-C02 Question 18
Single answerYou are developing an AWS Lambda function to process customer orders for an e-commerce application. Each invocation of the Lambda function processes a single order and does not rely on any data from previous executions. Which of the following best describes the behavior of the Lambda function?
- A
The Lambda function is stateful because it can retain data between invocations.
- B
The Lambda function is stateless because it does not retain data between invocations.
- C
The Lambda function is stateful because it uses environment variables.
- D
The Lambda function is stateless because it scales automatically based on demand.
Show answer and explanation
Correct answer: B
Explanation
AWS Lambda functions are stateless by design, meaning they do not retain any state or data between invocations. Each invocation is treated as an independent event, and any necessary state must be maintained externally using services like DynamoDB, S3, or other persistent storage. This stateless behavior allows Lambda to scale automatically and handle multiple invocations concurrently without concerns about shared state.
- A. Incorrect.
Incorrect: Lambda functions are inherently stateless, as they do not retain any data between invocations unless explicitly done using external storage services like DynamoDB or S3.
- B. Correct.
Correct: Lambda functions are stateless by design, meaning each invocation is independent and does not retain data from previous executions.
- C. Incorrect.
Incorrect: While environment variables can be used in a Lambda function, they do not make the function stateful. Environment variables are static and not tied to the state of the function across invocations.
- D. Incorrect.
Incorrect: Automatic scaling is a feature of Lambda but does not determine whether it is stateful or stateless. Statelessness refers to the lack of retained state between invocations.