DVA-C02 Development with AWS Services Practice Question
Exhibit
Refer to the exhibit. Error: Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'requests'
A developer is running a Lambda function that uses the 'requests' library. The error shown in the exhibit occurs when invoking the function. Which step should the developer take to fix this?
⚠ Common exam trap
Many candidates assume AWS Lambda runtimes include popular third-party libraries like 'requests', but in reality only the standard library is provided, so dependencies must be bundled manually.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Package the 'requests' library with the Lambda deployment package
The 'requests' library is not included in the AWS Lambda Python runtime by default. To use it, the developer must package the library as a dependency layer or include it in the deployment package. Option B correctly identifies this approach, ensuring the library is available at runtime.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Change the Lambda runtime to Python 3.9 which includes requests
Why it's wrong here
AWS Lambda runtimes, including Python 3.9, are designed to be lean and only include essential libraries like `boto3` and `urllib` by default. Third-party libraries such as `requests` are not pre-installed in the execution environment. This design choice ensures smaller runtime images and faster cold starts, requiring developers to explicitly bundle external dependencies rather than relying on the runtime to provide them.
- ✓
Package the 'requests' library with the Lambda deployment package
Why this is correct
To successfully use the `requests` library in an AWS Lambda function, it must be included as part of the deployment package. This typically involves installing `requests` and its dependencies into a local directory, then zipping that directory along with the function's handler code. Alternatively, for shared dependencies across multiple functions, a Lambda Layer can be created and attached, which is a best practice for managing common libraries efficiently.
- ✗
Use the 'urllib' library instead of 'requests'
Why it's wrong here
While the `urllib` library is a standard Python module available in all Lambda runtimes and can perform HTTP requests, it is generally less convenient and user-friendly than `requests`. Developers often prefer `requests` for its simpler API, automatic JSON handling, and robust error management, which significantly streamlines web interactions. Replacing `requests` with `urllib` would require rewriting existing code and sacrificing the ergonomic benefits that `requests` provides, which is not what the developer intends.
- ✗
Install the 'requests' library using pip in the Lambda console
Why it's wrong here
Attempting to install the `requests` library using `pip` directly within the Lambda console or during function execution is not a viable solution. The Lambda execution environment's file system is read-only for the function's code and dependencies, preventing persistent package installations at runtime. Dependencies must be pre-packaged with the deployment bundle or provided via a Lambda Layer before the function is invoked, as the console does not facilitate dynamic package management.
Quick reference
Cloud Service Model Comparison
| Model | You Manage | Provider Manages | Examples |
|---|---|---|---|
| IaaS | OS, runtime, apps, data | Hardware, hypervisor, networking | EC2, Azure VMs, GCP Compute Engine |
| PaaS | Apps and data | OS, runtime, middleware, hardware | Elastic Beanstalk, Azure App Service |
| SaaS | Data and settings only | Everything else | Microsoft 365, Salesforce, Workday |
| FaaS / Serverless | Function code only | Infra, scaling, runtime | Lambda, Azure Functions, Cloud Run |
| CaaS | Containers and apps | Kubernetes, OS, hardware | EKS, AKS, GKE |
Go deeper
Related to this question
About these practice questions
This DVA-C02 question is part of Courseiva's 724-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DVA-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DVA-C02 exam.