I have recently started to use AWS Lambda to use triggers against some python code I have written. I currently have 2 lambda functions, both of which have been created with
https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/
AWS removed the vendored version of requests
from Botocore.
Steps:
cmd >> pip install requests
Python code:
import requests
response = requests.get('https://...')
So this is what resolved in my case
Handler :: "yfinance_lamdba.lambda_handler"
In the above line
**yfinance_lamdba** is filename 'yfinance_script.py'
**lambda_handler** is function 'def lambda_handler' which has actual code
requests
library doesn't come by default in lambda. It looks like you are trying to import it in your function / library somewhere. To import it, you need the following line:
from botocore.vendored import requests
Alternatively, you would need to zip the requests
library in the root of your zip file.
EDIT: There may be a dependency in one of your libraries that may need this. To overcome this, install requests
in your application zip. To do this, run the following command in the root directory of your application: pip install requests -t ./
.
A better way would be to create a file called requirements.txt
and add all the dependencies in there. Use virtualenv to install all the packages defined in the requirements.txt using: pip install -r requirements.txt -t ./
UPDATE: Starting 10/21/19, the vendored version of the requests library in botocore will be removed. Refer this blog post for more details.
Give it a check to this answer
If you're working with Python on AWS Lambda, and need to use requests, you better use urllib3, it is currently supported on AWS Lambda and you can import it directly, check the example on urllib3 site.
import urllib3
http = urllib3.PoolManager()
r = http.request('GET', 'http://httpbin.org/robots.txt')
r.data
# b'User-agent: *\nDisallow: /deny\n'
r.status
# 200