A developer notices that a CloudWatch dashboard shows a Lambda function's Duration metric averaging 2,800 ms, which is close to the configured 3,000 ms timeout. The function loads a 150 MB ML model from S3 on every invocation. Increasing the timeout is not an option due to downstream API Gateway constraints. Which TWO changes will most directly reduce the average duration? (Select TWO)
- A. Load the ML model outside the Lambda handler function so it is cached in the execution environment across warm invocations.✓ Correct
- B. Increase the Lambda function's memory allocation from 512 MB to 3,008 MB.✓ Correct
- C. Store the ML model in an S3 Glacier Instant Retrieval storage class to reduce retrieval latency.
- D. Attach an Amazon EFS mount to the Lambda function and load the model from EFS instead of S3.
- E. Enable Lambda SnapStart for the function to restore pre-initialized execution environments.
- F. Switch the Lambda function trigger from API Gateway to an Application Load Balancer.
Explanation
Correct — Option B: Lambda CPU allocation scales linearly with memory. Increasing memory from 512 MB to 3,008 MB provides ~6× more CPU, which dramatically speeds up model loading and inference computation, directly reducing duration. Correct — Option A: Initializing the model outside the handler (in the global/module scope) causes it to be loaded once per execution environment. Subsequent warm invocations reuse the cached model object, skipping the S3 download entirely and cutting duration significantly. Wrong — Option C: S3 Glacier Instant Retrieval has the same retrieval speed for standard GET requests as S3 Standard for objects already restored, but Glacier is designed for archival data and would actually add complexity. The bottleneck here is the 150 MB download size, not the storage tier. Wrong — Option E: Lambda SnapStart is currently only supported for Java runtimes; it would not apply to most ML workloads and does not address the S3 download cost per invocation. Wrong — Option F: Changing the trigger from API Gateway to an ALB does not affect the duration of the Lambda function itself. Wrong — Option D: Loading from EFS instead of S3 may reduce latency for small files, but a 150 MB model still needs to be read on every invocation unless the model is also cached outside the handler — the caching strategy (Option A) is the key fix regardless of storage backend.