aiobotocore icon indicating copy to clipboard operation
aiobotocore copied to clipboard

Some tests fail if there are no AWS credentials

Open yan12125 opened this issue 2 years ago • 4 comments

Describe the bug

Several tests fail with botocore.exceptions.ConnectTimeoutError: Connect timeout on endpoint URL: "http://169.254.169.254/latest/api/token" if I don't provide AWS credentials. Specifically, with environment variable AWS_CONFIG_FILE=/dev/null some tests fail, and AWS_CONFIG_FILE=/my/aws/config makes all tests pass.

On tag 2.2.0, only test_can_delete_urlencoded_object fails, regardless of the value of $AWS_CONFIG_FILE. That test is known to be broken (https://github.com/aio-libs/aiobotocore/commit/643d041fcebb3f3867950bfb689493d394995246).

Here is the complete log, including commands to reproduce and outputs: log.txt

Checklist

  • [ ] I have reproduced in environment where pip check passes without errors - pipenv check reports some warnings about security issues in out-dated packages.
  • [x] I have provided pip freeze results - I include results from pipenv graph instead
  • [x] I have provided sample code or detailed way to reproduce
  • [ ] I have tried the same code in botocore to ensure this is an aiobotocore specific issue
  • [ ] I have tried similar code in aiohttp to ensure this is is an aiobotocore specific issue
  • [x] I have checked the latest and older versions of aiobotocore/aiohttp/python to see if this is a regression / injection

pip freeze results I included results from pipenv graph in the attached log

Environment:

  • Python Version: 3.10
  • OS name and version: Arch Linux up-to-date

Additional context I'm trying to upgrade the Arch Linux package python-aiobotocore. For version 2.2.0 all tests pass with the latest moto, while tests fail with similar botocore.exceptions.ConnectTimeoutError exceptions for newer versions. How dependencies are installed and tests are run are quite different from steps listed here, while I don't think that makes a difference.

yan12125 avatar Jun 25 '22 04:06 yan12125

thanks, will look when I get a chance, but also open to PRs :)

thehesiod avatar Jun 28 '22 15:06 thehesiod

Thanks! I guess a possible fix will be similar to https://github.com/aio-libs/aiobotocore/pull/941 as the stack trace is similar. I need more time to investigate.

yan12125 avatar Jun 29 '22 04:06 yan12125

If you're running localstack (or any of the kind) and don't want your tests to try and get credentials from AWS, try -

  1. set the environment variable AWS_EC2_METADATA_DISABLED = true
  2. aws_secret_access_key=test, aws_access_key_id=test (or anything else)

tomag avatar Jul 20 '22 16:07 tomag

Brilliant! The second approach works for me.

export AWS_SECRET_ACCESS_KEY=test
export AWS_ACCESS_KEY_ID=test

Actually it's already documented that running tests needs a pair of AWS key and secret. It will be nice if the document can further clarify that real credentials are not needed.

yan12125 avatar Jul 20 '22 19:07 yan12125

Alright, I arrived here after going through https://github.com/aio-libs/aiobotocore/pull/941, it is still an issue w/ aiobotocore==2.4.0 (the issue seems to be introduced after 2.2.0, because I had no issues w/ that version): I was getting botocore.exceptions.ConnectTimeoutError: Connect timeout on endpoint URL: "http://169.254.169.254/latest/api/token"

The solution mentioned above of declaring both AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID works :)

However, if this is required, a nice error telling that those values need to be set would be nice.

HacKanCuBa avatar Oct 12 '22 20:10 HacKanCuBa

I don't need the trick AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID anymore with aiobotocore 2.4.2. Maybe it's fixed along with exception normalization.

yan12125 avatar Dec 24 '22 09:12 yan12125