I need to do a rest-call within a python script, that runs once per day. I can't pack the "requests" package into my python-package using the AWS Lambdas. I get the error: "Unable to import module 'lambda_function': No module named lambda_function"
I broke it down to the hello_world predefined script. I can pack it into a zip and upload it. Everything works. As soon as I put "import requests" into the file, I get this error.
Here is what I already did:
The naming of everything looks like this:
The file I want to run in the end looks like this:
import requests import json def lambda_handler(event, context): url = 'xxx.elasticbeanstalk.com/users/login' headers = {"content-type": "application/json", "Authorization": "Basic Zxxxxxxxxx3NjxxZxxxxzcw==" } response = requests.put(url, headers=headers, verify=False) return 'hello lambda_handler'
I'm glad for ANY kind of help. I already used multiple hours on this issue.
Update (April 26, 2022):The version of the AWS SDK included in the AWS Lambda runtimes for Python 2.7, Python 3.6 and Python 3.7 will continue to include the 'requests' module in Botocore.
To resolve this error, create a deployment package or Lambda layer that includes the libraries that you want to use in your Python code for Lambda. Important: Make sure that you put the library that you import for Python inside the /python folder.
Overview. As we enter our third year of Python 2.7 reaching end-of-life, Requests has decided it's time to start deprecating our support. While we have yet to confirm a date, we want to provide early notice that this is coming at some point in 2022.
EDIT: On Oct-21-2019 Botocore removed the vendored version of requests: https://github.com/boto/botocore/pull/1829.
EDIT 2: (March 10, 2020): The deprecation date for the Lambda service to bundle the requests module in the AWS SDK is now January 30, 2021. https://aws.amazon.com/blogs/compute/upcoming-changes-to-the-python-sdk-in-aws-lambda/
To use requests module, you can simply import requests
from botocore.vendored
. For example:
from botocore.vendored import requests def lambda_handler(event, context): response = requests.get("https://httpbin.org/get", timeout=10) print(response.json())
you can see this gist to know more modules that can be imported directly in AWS lambda.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With