Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import failure on from boto3.s3.transfer import TransferConfig #3951

Closed
PSRCode opened this issue Nov 28, 2023 · 21 comments
Closed

Import failure on from boto3.s3.transfer import TransferConfig #3951

PSRCode opened this issue Nov 28, 2023 · 21 comments
Labels
bug This issue is a confirmed bug. closing-soon This issue will automatically close in 4 days unless further comments are made. dependencies This issue is a problem in a dependency. response-requested Waiting on additional information or feedback.

Comments

@PSRCode
Copy link

PSRCode commented Nov 28, 2023

Describe the bug

Hi,

Since Boto3 v1.33.0 we see a failure to import the following from our code application:

from boto3.s3.transfer import TransferConfig

Resulting in the following redacted Traceback:

/usr/local/lib/python3.10/dist-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
/usr/local/lib/python3.10/dist-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
    ???
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
/usr/local/lib/python3.10/dist-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
src/tests/test_s3bucket.py:2: in <module>
    from XXX.utils import s3_obj_helper
src/XXX/utils/s3_obj_helper.py:7: in <module>
    from boto3.s3.transfer import TransferConfig
/home/psrcode/.local/lib/python3.10/site-packages/boto3/s3/transfer.py:146: in <module>
    from boto3.crt import create_crt_transfer_manager
/home/psrcode/.local/lib/python3.10/site-packages/boto3/crt.py:26: in <module>
    from s3transfer.crt import (
/home/psrcode/.local/lib/python3.10/site-packages/s3transfer/crt.py:28: in <module>
    from awscrt.s3 import (
E   ImportError: cannot import name 'S3ResponseError' from 'awscrt.s3' (/usr/local/lib/python3.10/dist-packages/awscrt/s3.py)

The same import is working fine on 1.29.7.

Looking at the change log not much seems to be related apart from this:
* feature:``s3``: Boto3 will now opt into using the awscrt on select EC2 instance types for s3 transfers.

For now we will freeze our version locally to 1.29.7.

Cheers

Expected Behavior

The import should work.

Current Behavior

The import is broken.

Reproduction Steps

from boto3.s3.transfer import TransferConfig

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.33.0/1

Environment details (OS name and version, etc.)

Ubuntu 22.04.2

@PSRCode PSRCode added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Nov 28, 2023
@nateprewitt
Copy link
Contributor

Hi @PSRCode,

Thanks for reaching out about this. It looks like you may have an older version of the awscrt installed alongside Boto3.

With the release of Boto3 1.33.0, it requires awscrt==0.19.17 for certain functionality. The version of the awscrt you're using doesn't have these available, so the quickest fix is to upgrade the awscrt.

If that's not an option, you can disable boto3 using the awscrt with the BOTO_DISABLE_CRT environment variable. Let me know if these options aren't sufficient and we can talk more specifics.

@nateprewitt nateprewitt added response-requested Waiting on additional information or feedback. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 28, 2023
@PSRCode
Copy link
Author

PSRCode commented Nov 28, 2023

Hi @nateprewitt,

Thanks for the quick response. Ok, we will make sure to use awscrt > 0.19.17. I'll report back when I have some time to look into it. What's weird is that we do not define a version for "awscrt" in our requirement.txt so I would expect that we use latest.

Maybe a noob question, how would one should have "known" that we need that version. I would have expected boto3 to "enforce" the version for awscrt.

@nateprewitt
Copy link
Contributor

The awscrt is an optional dependency that Boto3 will use to optimize functionality if it's present. It's not (and currently can't be) a required dependency for Boto3. It should be kept up to date across AWS products that use it. The main other culprits would be the AWSCLI v2 and the AWS IoT SDK for Python v2.

As far as knowing, this feature has been in place for ~2 years and is intended to be a no-hassle opt-in. That does however make it harder to track for dependency management. If you know you're installing boto3 in conjunction with one of the other tools above, you can change your requirement to boto3[crt] which will ensure you always have the minimum required awscrt version.

We're discussing options to try to minimize (or ideally eliminate) these kinds of import issues with version mismatches and the awscrt going forward.

@nateprewitt nateprewitt added the dependencies This issue is a problem in a dependency. label Nov 28, 2023
@lisenet
Copy link

lisenet commented Nov 29, 2023

We've hit this very issue today on Amazon Linux 2023 that comes with python3-awscrt-0.16.7-1.amzn2023.0.1.

We can't easily upgrade awscrt as it's part of Beanstalk AMI, so the only workaround for now is to freeze our version of boto3 to 1.29.7.

@nateprewitt
Copy link
Contributor

Thanks for letting us know @lisenet. We found the CRT copy on AL2023 was outdated yesterday and are working on a fix to help mitigate that case. We'll provide an update here once that's available.

@davidrobertson
Copy link

Same @nateprewitt - the updated crt version is not yet available in the AWS repos. I'm willing to bet this broke a lot of things for a lot of organizations. We had to pin the older version of boto3 as well.

@lisenet
Copy link

lisenet commented Nov 29, 2023

My guess is that since boto3, awscrt and AL2023 are all Amazon software, there was no integration test that would include all three of them together. Otherwise this would've been picked up before releasing the code.

@nateprewitt
Copy link
Contributor

That's correct, AL2023 adding the CRT to the default Python setup was not a known integration point before yesterday. A quick note of clarity that boto3 should always be used in a virtualenv to avoid unintentional interactions with the default Python installation, but we're in the process of releasing a change to fix this now.

We expect this issue to be resolved in 1.33.3.

@lisenet
Copy link

lisenet commented Nov 29, 2023

Superb, appreciate the response.

@nateprewitt
Copy link
Contributor

Alright, 1.33.3 is published. I'll leave this open for a bit to gather any feedback/issues but will plan to close this tomorrow if we don't hear back. Thanks everyone for your patience.

@hsec
Copy link

hsec commented Nov 29, 2023

Evening. I've also been having an issue. I just updated and I'm still receiving the following error:

ImportError: cannot import name 'S3ResponseError' from 'awscrt.s3' (/usr/local/lib/python3.12/site-packages/awscrt/s3.py)

Installed is the following:

pip freeze | grep awscrt -------> awscrt==0.19.18

pip freeze | grep boto3. -------> boto3==1.33.3

It's probably me, however all was good last week.

Many thanks for any help you could provide.

@nateprewitt
Copy link
Contributor

Hi @hsec, yes this was from a change made yesterday. What version of s3transfer do you have installed? If it's not the latest, 0.8.2 you will still have this issue.

@hsec
Copy link

hsec commented Nov 29, 2023

Hi. Thank you for responding. I have 0.8.1. I ran pip install s3transfer>=0.8.2, but no update was available.

@nateprewitt
Copy link
Contributor

0.8.2 should be available on PyPI.

Also to double check from what you wrote above, you're using pip freeze to display versions. Is this error happening locally or on Lambda? S3ResponseError is available in awscrt>=0.19.11 so the version of CRT being used isn't what's displayed in pip freeze.

@hsec
Copy link

hsec commented Nov 30, 2023

Hi. This error is local. I successfully installed the 0.8.2 version:

Uninstalling s3transfer-0.8.1:
Successfully uninstalled s3transfer-0.8.1
Successfully installed s3transfer-0.8.2

and the previous error has gone away.

I do however now get a S3ResponseError:

ImportError: cannot import name 'S3ResponseError' from 'awscrt.s3' (/usr/local/lib/python3.12/site-packages/awscrt/s3.py)

Perhaps I'm doing something incorrectly.

Do I need to update all of the components to the latest version?

@nateprewitt
Copy link
Contributor

You'll either need everything with the current requirements or the older ones. You won't be able to mix old and new. If you start a fresh virtualenv and pip install boto3[crt] are you still getting the error?

i.e.

python -m venv .venv
source .venv/bin/activate
python -m pip install "boto3[crt]"
python -c 'import awscrt;import boto3;import botocore;import s3transfer;print(f"Boto3: {boto3.__version__}, Botocore: {botocore.__version__}, S3Transfer: {s3transfer.__version__}, CRT: {awscrt.__version__}")'

If the above still fails, you may try these one at a time:

python -c 'import awscrt; print(f"CRT: {awscrt.__version__}")'
python -c 'import boto3; print(f"Boto3: {boto3.__version__}")'
python -c 'import botocore; print(f"Botocore: {botocore.__version__}")'
python -c 'import s3transfer; print(f"Botocore: {botocore.__version__}")'

@hsec
Copy link

hsec commented Nov 30, 2023

Unfortunately, I'm still getting the same error.

@hsec
Copy link

hsec commented Nov 30, 2023

What version of the modules (in their entirety), still work, and wha would be the besrt way to about that?

Many thanks in advance.

@hsec
Copy link

hsec commented Nov 30, 2023

Good morning. I uninstalled boto3 (1.33.3) and installed version 1.33.4 and all is good again. Thank you again for your patience and rapid response.

@nateprewitt
Copy link
Contributor

Great to hear, @hsec. I'm going to put this in auto-resolve since the original issue is no longer reproducible and we haven't heard back on further issues in the last 24 hours.

@nateprewitt nateprewitt added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Nov 30, 2023
Copy link

github-actions bot commented Dec 5, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. closing-soon This issue will automatically close in 4 days unless further comments are made. dependencies This issue is a problem in a dependency. response-requested Waiting on additional information or feedback.
Projects
None yet
Development

No branches or pull requests

5 participants