Lambda Layer failing due to circular import

0

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?

asked 8 months ago263 views
1 Answer
0

Hello.

It might be a dependency issue with urllib3.
Will it work if I add "urllib3<2" when doing pip installation?
https://github.com/psf/requests/issues/6443

profile picture
EXPERT
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions