I created a Lambda function (Python 3.11) and added a layer with requests
package. But now, when I try to import it, I get the following error:
Unable to import module 'lambda_function': cannot import name 'HTTPConnectionPool' from partially initialized module 'urllib3.connectionpool' (most likely due to a circular import) (/opt/python/urllib3/connectionpool.py)
To create my layer.zip file, I first downloaded the package into a directory named python:
pip install \
--platform manylinux2014_x86_64 \
--target=python \
--implementation cp \
--python 3.11 \
--only-binary=:all: --upgrade \
requests
Then I zipped the python/ directory and uploaded it to my AWS Layers. And my Lambda function code is very simple:
import json
import requests
def lambda_handler(event, context):
return {
"statusCode": "200"
}
How can I use requests package in my Lambda?