DVA-C02 Question 307
Single answerYou are developing an AWS Lambda function written in Python, and it has multiple dependencies, including some that are not available in the default Lambda runtime. Which of the following deployment packaging options should you choose to ensure all dependencies are properly included during deployment?
- A
Include your Python code and dependencies in a .zip file and upload it directly to Lambda.
- B
Use the AWS Lambda console to specify external dependencies, and Lambda will install them during execution.
- C
Create a deployment package with your code and dependencies using an Amazon Linux environment, and upload it to an S3 bucket.
- D
Specify the dependencies in a requirements.txt file and upload only the file to Lambda.
Show answer and explanation
Correct answer: A
Explanation
When developing an AWS Lambda function with dependencies not included in the default runtime, you must package your code and dependencies together in a .zip file. This ensures that all necessary files are available when the Lambda function executes. While tools like Amazon Linux environments can help ensure compatibility, the central requirement is to include everything in the deployment package.
- A. Correct.
This is the correct way to package a Lambda function with dependencies. You need to include both your code and all required dependencies in a .zip file when the dependencies are not available in the default runtime.
- B. Incorrect.
This is incorrect. The Lambda console does not have the functionality to automatically detect and install external dependencies during execution.
- C. Incorrect.
While creating the package in an Amazon Linux environment is important for compatibility with the Lambda runtime, the correct step is to upload the .zip package directly to Lambda or via an S3 bucket. This option is incomplete and misleading.
- D. Incorrect.
This is incorrect. Uploading only a requirements.txt file to Lambda will not automatically install the dependencies for your function. You need to package them together manually.