- Newest
- Most votes
- Most comments
We faced a similar issue, resolved by setting the version of both boto3 and botocore in requirements.txt and shipping as part of the vendor dependencies.
What I think is going on, the Lambda function's default/built-in/baked-in dependencies of boto3 and botocore are mismatched, such that boto3 is using latest version (1.33.2) but botocore is using a previous version (1.33.1).
I tested this hypothesis and was able to reproduce the issue:
(venv5) Braverman@Local ~/Repos/apply-api (set-boto-version-1.33.1) $ pip list | grep boto
boto3 1.33.2
botocore 1.33.1
(venv5) Braverman@Local ~/Repos/apply-api (set-boto-version-1.33.1) $ python
Python 3.8.3 (default, Jul 8 2020, 14:27:55)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
s3 = boto3.resource("s3")
>>> s3 = boto3.resource("s3")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
ImportError: cannot import name 'is_s3express_bucket' from 'botocore.utils' (/Users/steven.braverman/Repos/apply-api/venv5/lib/python3.8/site-packages/botocore/utils.py)
However, if I match up the environments, things run smoothly:
(venv5) Braverman@Local ~/Repos/apply-api (master) $ pip list | grep boto
boto3 1.33.2
botocore 1.33.2
>>> import boto3
s3 = boto3.resource("s3")
>>> s3 = boto3.resource("s3")
>>>
It is interesting that the new version of Lambda you deployed is not facing this issue. Deploying the new lambda function must have triggered a pip install -U on the lambda function's dependencies, which seems to not occur for already existing lambda functions.
There seems to be something off with your versions. Where are you printing those versions from? What is odd is that the "s3express" method that is causing the exception is something that was added with the latest version of botocore/boto3 (on 2023.11.28) in version 1.33.2.
It would be strange that older versions of botocore/boto3 are complaining about "s3express" when "s3express" does not exist until 1.33.2 https://github.com/boto/botocore/commit/af4fdde1a2e053f3d9d9d91e7ad13167388528ce
boto3.version='1.26.90' botocore.version='1.29.90'
I got the output from the following code in the lambda.
import boto3 import botocore print(f"{boto3.__version__=}") print(f"{botocore.__version__=}")
The error seems to come from a sub package of boto3, s3transfer. It appears that this has started supporting s3express in 0.8.1. I tried to fix the version of s3transfer only, then it seems to work for me.
The answer above is correct. We also faced this issue because we were packing s3transfer
from our local development environment with the Lambda function, while boto
and botocore
were coming from the Lambda environment.
The solution for us was to either use all of the libraries from the runtime (built-in) or package all of them with the function code. Went for the first one and it worked.
Relevant content
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
- How can I use a Lambda function to automatically start an AWS Glue job when a crawler run completes?AWS OFFICIALUpdated 2 years ago
Thanks for your comment.
I agree with your guess. Specifying versions of both boto3 and botocore will solve the problem. It would be nice if we could control the boto3 version, but we have removed boto3 and botocore from our SAM build due to lambda code size limitations.
Note that the versions of boto3 and botocore were not the latest(1.26.90 and 1.29.90), and they were the same as another lambda that does not cause the error.
I tried to add the following to my requirements.txt, instead of specifying boto3 and botocore versions, and I got the lambda succeeded.
Because is_s3express_bucket is added in https://github.com/boto/s3transfer/commit/3b50c31bb608188cdfb0fc7fd8e8cd03b6b7b187