Question #601
A developer is building a serverless application with two AWS Lambda functions for video processing. The first Lambda function uploads video files to an Amazon S3 bucket and records processing parameters in an Amazon DynamoDB table. The second Lambda function retrieves the videos from S3 using the DynamoDB metadata and applies transformations. Both functions rely on the same large machine learning library for video analysis, causing their deployment packages to approach the AWS Lambda size limit.
What should the developer do to minimize the deployment package sizes while maintaining separation of concerns and reducing operational complexity?
Separately package the machine learning library with each Lambda function in individual .zip files, maintaining independent deployments.
Create a shared Lambda layer containing the machine learning library and attach it to both Lambda functions.
Merge both Lambda functions into a single function with conditional logic, deployed as one .zip archive.
Store the machine learning library in an S3 bucket and configure Lambda functions to download it during execution.
Explanation
Answer B is correct because AWS Lambda layers enable sharing common dependencies (like the ML library) across multiple Lambda functions. By creating a shared layer:
1. Reduced Deployment Size: The library is stored once in the layer, avoiding duplication in each function's deployment package.
2. Separation of Concerns: Both Lambda functions remain independent, each focusing on their specific tasks (uploading vs. processing).
3. Operational Simplicity: Updates to the library only require updating the layer, not each function.
Why other options are incorrect:
- A: Packaging the library separately with each function duplicates the library, increasing deployment sizes and maintenance effort.
- C: Merging functions violates separation of concerns and complicates scaling/logic.
- D: Downloading the library from S3 during execution introduces latency, adds runtime overhead, and risks hitting Lambda's /tmp storage limits.
Key Takeaway: Lambda layers are the AWS-recommended solution for managing shared dependencies across functions, optimizing deployment size, and reducing redundancy.
Answer
The correct answer is: B