A company's Lambda function runs 10 million times a month at about 200 ms per invocation with 512 MB of memory, and the Lambda bill is higher than budgeted. Which optimization reduces Lambda costs most?
Show answer and explanation
Answer: B
Lambda bills GB-seconds: allocated memory multiplied by execution time. Halving execution duration from 200 ms to 100 ms halves the charge outright, and a validated memory reduction from 512 MB to 256 MB halves it again for a combined cut near 75%. Code efficiency is the largest lever on the billed duration; memory right-sizing follows.
Why the other options are wrong
- A. The timeout is merely a kill switch — a run finishing in 200 ms bills the same no matter where the timeout is set, and anything slower now fails outright.
- C. Provisioned Concurrency keeps environments pre-warmed at an added hourly cost while the invocation count and duration are unchanged, so spending goes up.
- D. arm64 rates are around 20% lower, but an untested architecture swap risks dependency incompatibility or slower billed runtime, and the achievable gain is small compared with halving duration and memory.