79623878

Date: 2025-05-15 17:04:53
Score: 6 🚩
Natty:
Report link

Meanwhile I also tried to used custom session boto3 like below:

from boto3.session import Session as Boto3Session
from botocore.config import Config
from botocore.httpsession import URLLib3Session
from botocore.session import Session as BotocoreSession

class CustomURLLib3Session(URLLib3Session):  # type: ignore[misc]
    def __init__(self, config: CloudSecurityWorkerConfigs):
        if config.USE_KRAKEN:
            log.info(f'proxy: {config.KRAKEN_PROXY}')
            cert_key = get_app_certs()
            if cert_key:
                cert, key = cert_key
                log.info(f'cert: {cert}, key: {key}')
            super().__init__(
                proxies=config.KRAKEN_PROXY,
                verify='<ca-bundle>.crt',
                proxies_config={
                    'proxy_ca_bundle': '<ca-bundle>.crt',
                    'proxy_client_cert': cert_key,
                },
            )
        else:
            super().__init__()
botocore_session = BotocoreSession()
        botocore_session.register_component('httpsession', CustomURLLib3Session(config))
        boto3_session = Boto3Session(botocore_session=botocore_session)

        # Optional: set retries or other config options
        s3_config = Config(retries={'max_attempts': 6, 'mode': 'standard'})

        # Create the S3 client using the patched session
        test_aws_client = boto3_session.client(
            's3',
            aws_access_key_id=config.AWS_ACCESS_KEY_ID,
            aws_secret_access_key=config.AWS_ACCESS_SECRET_KEY,
            config=s3_config,
        )
        log.info(f'client created: {test_aws_client}')
        paginator = test_aws_client.get_paginator('list_objects_v2')

But I get below error:

2025-05-15 13:21:46,740 cloudsecurityworker.worker [ERROR] Failed to connect to aws: Could not connect to the endpoint URL: "https://<bucket_name>.s3.amazonaws.com/?list-type=2&prefix=dummy%2F&encoding-type=url"
Traceback (most recent call last):
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/connection.py", line 198, in _new_conn
    sock = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/util/connection.py", line 85, in create_connection
    raise err
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/httpsession.py", line 464, in send
    urllib_response = conn.urlopen(
                      ^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/connectionpool.py", line 841, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/util/retry.py", line 449, in increment
    raise reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/util/util.py", line 39, in reraise
    raise value
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/connectionpool.py", line 488, in _make_request
    raise new_e
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/connectionpool.py", line 464, in _make_request
    self._validate_conn(conn)
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/connectionpool.py", line 1093, in _validate_conn
    conn.connect()
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/connection.py", line 704, in connect
    self.sock = sock = self._new_conn()
                       ^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/urllib3/connection.py", line 213, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <botocore.awsrequest.AWSHTTPSConnection object at 0x71393f4fea90>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/cloudsecurityworker/worker.py", line 84, in main
    for page in page_iterator:
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/paginate.py", line 269, in __iter__
    response = self._make_request(current_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/paginate.py", line 357, in _make_request
    return self._method(**current_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/client.py", line 565, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/client.py", line 999, in _make_api_call
    http, parsed_response = self._make_request(
                            ^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/client.py", line 1023, in _make_request
    return self._endpoint.make_request(operation_model, request_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/endpoint.py", line 119, in make_request
    return self._send_request(request_dict, operation_model)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/endpoint.py", line 229, in _send_request
    raise exception
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/endpoint.py", line 279, in _do_get_response
    http_response = self._send(request)
                    ^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/endpoint.py", line 375, in _send
    return self.http_session.send(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/export/content/lid/apps/cloud-security-worker/i001/libexec/cloud-security-worker.pyz_121b45119d28139a516068d60967f047fbfa1bb51f837990300dd4a0099e35f2/site-packages/botocore/httpsession.py", line 493, in send
    raise EndpointConnectionError(endpoint_url=request.url, error=e)
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://<bucket_name>.s3.amazonaws.com/?list-type=2&prefix=dummy%2F&encoding-type=url"

I am stuck on how to resolve this issue?

Reasons:
  • RegEx Blacklisted phrase (1.5): I am stuck
  • RegEx Blacklisted phrase (1.5): how to resolve this issue?
  • RegEx Blacklisted phrase (1): I get below error
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Struggler