AWS Lambda
Python error
urllib3
DEFAULT_CIPHERS
Lambda layers

cannot import name 'DEFAULT_CIPHERS' from 'urllib3.util.ssl_' on AWS Lambda using a layer

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

This Lambda error is usually a dependency mismatch, not a TLS problem. Something in your function or layer expects an older internal symbol from urllib3, but the version actually loaded at runtime no longer contains it.

The important detail is that DEFAULT_CIPHERS came from a private urllib3 module path. Private internals are not stable, and AWS Lambda layers make version conflicts easier to create because they can shadow packages that already exist in the runtime.

Why the Import Fails

The failing import usually looks like this:

python
from urllib3.util.ssl_ import DEFAULT_CIPHERS

That import worked with older urllib3 versions, but urllib3 2.x removed or reorganized internals that many older packages assumed still existed. If your layer contains urllib3 2.x but some dependency was built against urllib3 1.x expectations, the import fails immediately.

In Lambda, that mismatch commonly happens because:

  • a layer ships urllib3 separately from requests, botocore, or another dependency
  • the runtime already has AWS SDK packages, and your layer overrides only part of that stack
  • the layer was built with dependency versions that work locally but not together in Lambda

The Most Common Fix: Pin Compatible Versions

If one of your packages still expects older urllib3 internals, pin urllib3 to a compatible major version when building the layer:

bash
1mkdir -p python
2pip install \
3  "requests==2.31.0" \
4  "urllib3<2" \
5  -t python/
6
7zip -r layer.zip python

That keeps requests and urllib3 aligned in the layer instead of mixing a newer urllib3 with an older dependency chain.

Be Careful with Lambda's Built-in AWS SDK

Lambda runtimes often include boto3 and botocore. If your layer provides only one of their dependency pieces, you can accidentally create an inconsistent import graph.

A safer pattern is:

  • either ship the whole dependency stack yourself
  • or ship none of it and rely on the runtime copy

Mixing runtime packages with partially overridden layer packages is where many of these import errors come from.

Verify What Version Lambda Actually Loaded

Add a short diagnostic to the function temporarily:

python
1import urllib3
2import requests
3
4def lambda_handler(event, context):
5    return {
6        "urllib3": urllib3.__version__,
7        "requests": requests.__version__,
8    }

If the runtime reports a version you did not expect, the layer or deployment package is shadowing something.

Build the Layer for the Right Runtime

Lambda layers should be built with the same Python major and minor version as the function runtime. The packaging path also matters. For Python, the wheel contents should live under a python/ directory in the zip archive.

For example:

text
1layer.zip
2└── python/
3    ├── requests/
4    ├── urllib3/
5    └── ...

If the structure is wrong, imports can fail in different ways and make the dependency problem harder to recognize.

Using a locked requirements.txt or pip-tools output also helps because it makes the exact layer contents reproducible across rebuilds.

Common Pitfalls

  • Upgrading urllib3 alone without checking whether the rest of the dependency stack supports it.
  • Importing private internals from urllib3.util.ssl_ directly in your own code.
  • Shipping only part of the requests or AWS SDK dependency chain in a Lambda layer.
  • Assuming the versions installed locally are the same ones Lambda actually loads.
  • Building a layer with the wrong directory structure or the wrong Python runtime.

Summary

  • This error usually means a package expects an older urllib3 internal symbol that is no longer present.
  • On Lambda, layers often trigger the problem by shadowing runtime packages with incompatible versions.
  • The safest fix is usually to pin compatible versions, often with urllib3<2 for older dependency stacks.
  • Avoid importing private urllib3 internals directly in application code.
  • Check the actual versions loaded inside Lambda before changing unrelated TLS settings.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design