boto / boto3

AWS SDK for Python
https://aws.amazon.com/sdk-for-python/
Apache License 2.0
8.99k stars 1.86k forks source link

Invalid endpoint when initializing boto3.client inside Docker #4209

Closed lpares12 closed 2 months ago

lpares12 commented 2 months ago

Describe the bug

When running an application using boto3 inside a docker, the boto3.client() URL gives an "Invalid endpoint" error. Outside of the docker, there's no error.

Expected Behavior

I'd expect the boto3.client to work exactly the same as outside of the docker, so there should not be an error.

Current Behavior

    self.client = boto3.client(
                  ^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/boto3/__init__.py", line 92, in client
    return _get_default_session().client(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/boto3/session.py", line 297, in client
    return self._session.create_client(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/botocore/session.py", line 997, in create_client
    client = client_creator.create_client(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/botocore/client.py", line 161, in create_client
    client_args = self._get_client_args(
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/botocore/client.py", line 520, in _get_client_args
    return args_creator.get_client_args(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/botocore/args.py", line 137, in get_client_args
    endpoint = endpoint_creator.create_endpoint(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/botocore/endpoint.py", line 402, in create_endpoint
    raise ValueError("Invalid endpoint: %s" % endpoint_url)
ValueError: Invalid endpoint: "https://myUserId.r2.cloudflarestorage.com"

Where myUserId is my Cloudflare user ID.

Reproduction Steps

Create an Ubuntu docker container that has boto3 installed and run:

    def init_client(self, access_key, access_key_id, endpoint, region: str = 'auto'):
        self.client = boto3.client(
            service_name='s3',
            endpoint_url=endpoint,
            aws_access_key_id=access_key_id,
            aws_secret_access_key=access_key,
            config=Config(signature_version='s3v4'),
            region_name=region
        )

These are the commands I use for creating the container and running it:

sudo docker build -t monitoring .
sudo docker run --env-file .env monitoring

Possible Solution

No response

Additional Information/Context

I have also tried to check manually for the URL, with the call boto3core.utils.is_valid_endpoint_url and it seems okay when run as a standalone call:

from botocore import utils

print(utils.is_valid_endpoint_url('https://myUserId.r2.cloudflarestorage.com'))

Results in:

$ sudo docker run --env-file .env monitoring
<re.Match object; span=(0, 57), match='myUserId.r2.cloudflaresto>

Which is exactly the same output I have in my computer outside of Docker.

SDK version used

boto3.1.34.145

Environment details (OS name and version, etc.)

Docker with ubuntu 24.04 image

lpares12 commented 2 months ago

Agh, sorry for the noise. I see now there's an extra " in the environment variables entered in the .env file.

github-actions[bot] commented 2 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.