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.
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:
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
urllib3separately fromrequests,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:
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:
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:
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
urllib3alone 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
requestsor 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
urllib3internal 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<2for older dependency stacks. - Avoid importing private
urllib3internals directly in application code. - Check the actual versions loaded inside Lambda before changing unrelated TLS settings.
Related reading
- Cannot ping AWS EC2 instance
- Cannot read credentials from /.aws/credentials - PHP script call AWS-SDK
- Cannot return null for non-nullable type 'Person' within parent 'Messages' /getMessages/sendBy in GraphQL SDL aws appsync
- Cannot use Requests-Module on AWS Lambda
- Cannot import name 'dtensor' from 'tensorflow.compat.v2.experimental
- Cannot import name 'load_img' from 'keras.preprocessing.image
- Can't connect to RDS instance from EC2 instance
- Can't connect to RDS PostgreSQL DB instance through an RDS proxy

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.