Q48 — AWS DVA-C02 Ch.1

Question 48 of 100 | ← Chapter 1

A developer created an AWS Lambda function that accesses resources in a VPC. The Lambda function polls an Amazon Simple Queue Service (Amazon SQS) queue via a VPC endpoint to retrieve new messages. Then, the function computes the rolling average of numeric values contained in the messages. After initial testing of the Lambda function, the developer finds the returned rolling average is inaccurate. How can the developer ensure the function computes an accurate rolling average?

Correct Answer: B. Modify the function to store values in Amazon ElastiCache. On function initialization, compute the rolling average using prior values from the cache.

Explanation

Modify the function to store values in Amazon ElastiCache. On function initialization, compute the rolling average using prior values from the cache. This solution modifies the Lambda function to store numeric values in Amazon ElastiCache and compute the rolling average during initialization using cached prior values. This is effective because ElastiCache serves as persistent, shared state storage across Lambda invocations. Even if Lambda execution environments are destroyed and recreated between invocations, values in ElastiCache persist. Option C — setting reserved concurrency to 1 and storing the rolling average in ElastiCache — is also valid, ensuring only one concurrent instance runs and leveraging caching for accuracy and performance. Both options are viable; the final choice depends on architectural requirements and developer preference. 【Lantern Certification provided by: swufelp1999】