runtime error for lambda running on python3.7 and urllib3-1.21.1 = "cannot import name 'is_ipaddress' from 'urllib3.util.ssl_' (/var/task/urllib3/util/ssl_.py)"

0

Why I started getting this "cannot import name 'is_ipaddress' from 'urllib3.util.ssl_' (/var/task/urllib3/util/ssl_.py)" as there was no change/deployment in lambda package by us. We fixed the issue by rebuilding the environment however we are still not sure why we got this error, is there any release from AWS in boto3 library which changed the lambda environment and which is not compatible with urllib3 1.21.1. That triggered this error. We are using boto3 to connect to S3 and dynamoDB.

** Further details: **

All of sudden, since may 11,2023, I am getting this error for my long running lambda on python3.7 and urllib3 1.21.1

** "cannot import name 'is_ipaddress' from 'urllib3.util.ssl_' (/var/task/urllib3/util/ssl_.py)"**

To fix this issue, I rebuilt the virtual environment and repackaged the lambda with python3.7 and urllib3 version got upgraded to urllib3 1.26.16 from 1.21.1. This fixed the issues since urllib3 1.26.16 has is_ipaddress method:

def is_ipaddress(hostname):
    """Detects whether the hostname given is an IPv4 or IPv6 address.
    Also detects IPv6 addresses with Zone IDs.

    :param str hostname: Hostname to examine.
    :return: True if the hostname is an IP address, False otherwise.
    """
    if not six.PY2 and isinstance(hostname, bytes):
        # IDN A-label bytes are ASCII compatible.
        hostname = hostname.decode("ascii")
    return bool(IPV4_RE.match(hostname) or BRACELESS_IPV6_ADDRZ_RE.match(hostname))

Can you please help me with what made the urllib3 1.21.1 incompatible in the existing lambda which was running smoothly before.

asked 10 months ago1399 views
1 Answer
0

AWS can and will regularly update the underlying python libraries such at boto3.

This may not be the answer you’re looking for though may help for the future.

It’s best to create an immutable layer to lock your version in. I personally have my own boto3 layer which is newer than AWS’s

More details can be found here https://docs.aws.amazon.com/lambda/latest/operatorguide/sdks-functions.html

https://docs.aws.amazon.com/lambda/latest/dg/lambda-python.html#

profile picture
EXPERT
answered 10 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