A Lambda function running in a VPC polls an SQS queue via a VPC endpoint, then computes a rolling average of numeric values from messages. Initial tests show the rolling average is inaccurate. How can the developer ensure an accurate rolling average?
Choose an answer
Tap an option to check your answer.
Correct answer: Set the function's reserved concurrency to 1. Compute the rolling average in the function and store the calculated rolling average in Amazon ElastiCache..
Why this is the answer
Setting reserved concurrency to 1 ensures only one instance of the Lambda function runs at any given time, preventing race conditions that would lead to an inaccurate rolling average when multiple instances try to update the average concurrently. Storing the calculated rolling average in Amazon ElastiCache provides a shared, fast, and persistent data store for the single function instance to read and write the current average, maintaining state across invocations. Modifying the function to store incoming values in ElastiCache and computing on initialization is less efficient as it re-computes the entire average each time. Provisioned concurrency guarantees a minimum number of pre-initialized execution environments but doesn't limit the maximum, so it wouldn't prevent multiple instances from running. Storing values in layers is incorrect because layers are for code and dependencies, not dynamic data storage, and are read-only during invocation.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed