DVA-C02 Question 227
Single answerYou are developing an AWS Lambda function that requires access to a large, external library for data processing. The library size exceeds the deployment package limit of 50 MB when compressed. How can you include this library in your Lambda function while staying within AWS Lambda's deployment package size limits?
- A
Include the library in a Lambda layer and configure your function to use the layer.
- B
Compress the library further and include it in the deployment package.
- C
Split the library into smaller parts and upload each part as a separate Lambda function.
- D
Use Amazon S3 to store the library and download it within the Lambda function during execution.
Show answer and explanation
Correct answer: A
Explanation
The best way to include a large external library in your AWS Lambda function is by using Lambda layers. Layers allow you to package and share common code, libraries, or dependencies across multiple Lambda functions without including them in the deployment package. This not only helps you stay within deployment package size limits but also improves maintainability and reduces redundancy.
- A. Correct.
Correct. Lambda layers are specifically designed to allow you to include external libraries, dependencies, or other custom code that can be shared across multiple Lambda functions. This approach helps you stay within the deployment package size limits.
- B. Incorrect.
Incorrect. AWS Lambda has a hard limit of 50 MB for the compressed deployment package size, and further compression would not solve this issue as it would likely still exceed the limit.
- C. Incorrect.
Incorrect. Splitting the library into smaller parts and creating multiple Lambda functions is not an effective solution. Lambda functions are not inherently designed to share code or work in this manner.
- D. Incorrect.
Incorrect. While storing the library in S3 and downloading it during execution is technically possible, it would significantly increase the cold start time and execution time of the Lambda function, which is not ideal for performance.