DVA-C02 Question 305
Select 2You are developing an AWS Lambda function to process image uploads. The function uses a custom library for image manipulation that is not included in the default AWS Lambda runtime. The library requires specific native dependencies. How should you package and deploy the Lambda function to ensure all dependencies are included and compatible?
- A
Use the AWS Management Console to directly paste the function code and rely on Lambda to automatically install the required dependencies.
- B
Package the function code and dependencies into a ZIP file locally, ensuring the dependencies are compiled for the Lambda runtime environment, and upload it to Lambda.
- C
Use AWS Serverless Application Model (SAM) or AWS CloudFormation to package and deploy the Lambda function without explicitly handling the dependencies.
- D
Use a Docker container image to package the function code and dependencies, ensuring they are compatible with the Lambda runtime environment, and deploy the image to Lambda.
Show answer and explanation
Correct answers: B, D
Explanation
AWS Lambda supports two main deployment packaging options: ZIP archives and container images. For ZIP deployments, you must ensure all dependencies, including native ones, are included and compatible with the Lambda runtime environment. For container image deployments, you can package your function code and dependencies into a Docker image, which provides more flexibility for custom dependencies and runtime compatibility. Both approaches are valid for handling native dependencies, but using the AWS Management Console or relying solely on SAM/CloudFormation does not handle dependency packaging.
- A. Incorrect.
AWS Lambda does not automatically install dependencies for code pasted directly into the Management Console. Instead, you must package and include dependencies yourself.
- B. Correct.
Packaging the function code and dependencies into a ZIP file locally is a valid method, but you must ensure the dependencies are compiled for the Lambda runtime environment (e.g., Amazon Linux).
- C. Incorrect.
While SAM and CloudFormation can help deploy Lambda functions, they do not automatically package native dependencies or ensure compatibility with the runtime.
- D. Correct.
Using a Docker container image is another valid approach, especially for functions with custom dependencies, as you can build the image to include all necessary libraries and ensure compatibility with the Lambda runtime environment.