    async def set_session(self, refresh=False, kwargs={}):
        """Establish S3 connection object.

        This async method is called by any operation on an ``S3FileSystem`` instance.
        The ``refresh=True`` argument is useful if new credentials have been created
        and the instance needs to be reestablished. ``connect`` is a blocking
        version of ``set_session``.

        Parameters
        ----------
        refresh : bool (False)
            If True, create a new session even if one already exists.
        kwargs : dict
            Currently unused.

        Returns
        -------
        Session to be closed later with await .close()

        Examples
        --------
        >>> s3 = S3FileSystem(profile="<profile name>")  # doctest: +SKIP
        # use in an async coroutine to assign the client object to a local variable
        >>> await s3.set_session()  # doctest: +SKIP
        # blocking version of set_session
        >>> s3.connect(refresh=True)  # doctest: +SKIP
        """
        if self._s3 is not None and not refresh:
            return self._s3
        logger.debug("Setting up s3fs instance")

        client_kwargs = self.client_kwargs.copy()
        init_kwargs = dict(
            aws_access_key_id=self.key,
            aws_secret_access_key=self.secret,
            aws_session_token=self.token,
            endpoint_url=self.endpoint_url,
        )
        init_kwargs = {
            key: value
            for key, value in init_kwargs.items()
            if value is not None and value != client_kwargs.get(key)
        }
        if "use_ssl" not in client_kwargs.keys():
            init_kwargs["use_ssl"] = self.use_ssl
        config_kwargs = self._prepare_config_kwargs()
        if self.anon:
            from botocore import UNSIGNED

            drop_keys = {
                "aws_access_key_id",
                "aws_secret_access_key",
                "aws_session_token",
            }
            init_kwargs = {
                key: value for key, value in init_kwargs.items() if key not in drop_keys
            }
            client_kwargs = {
                key: value
                for key, value in client_kwargs.items()
                if key not in drop_keys
            }
            config_kwargs["signature_version"] = UNSIGNED

        conf = AioConfig(**config_kwargs)
        if self.session is None or refresh:
            self.session = aiobotocore.session.AioSession(**self.kwargs)

        for parameters in (config_kwargs, self.kwargs, init_kwargs, client_kwargs):
            for option in ("region_name", "endpoint_url"):
                if parameters.get(option):
                    self.cache_regions = False
                    break
        else:
            cache_regions = self.cache_regions

        logger.debug(
            "RC: caching enabled? %r (explicit option is %r)",
            cache_regions,
            self.cache_regions,
        )
        self.cache_regions = cache_regions
        if self.cache_regions:
            s3creator = S3BucketRegionCache(
                self.session, config=conf, **init_kwargs, **client_kwargs
            )
            self._s3 = await s3creator.get_client()
        else:
            s3creator = self.session.create_client(
                "s3", config=conf, **init_kwargs, **client_kwargs
            )
            self._s3 = await s3creator.__aenter__()

        self._s3creator = s3creator
        # the following actually closes the aiohttp connection; use of privates
        # might break in the future, would cause exception at gc time
        if not self.asynchronous:
            weakref.finalize(self, self.close_session, self.loop, self._s3creator)
        self._kwargs_helper = ParamKwargsHelper(self._s3)
        return self._s3
Establish S3 connection object.

This async method is called by any operation on an ``S3FileSystem`` instance.
The ``refresh=True`` argument is useful if new credentials have been created
and the instance needs to be reestablished. ``connect`` is a blocking
version of ``set_session``.

Parameters
----------
refresh : bool (False)
If True, create a new session even if one already exists.
kwargs : dict
Currently unused.

Returns
-------
Session to be closed later with await .close()

Examples
--------
>>> s3 = S3FileSystem(profile="<profile name>")  # doctest: +SKIP
# use in an async coroutine to assign the client object to a local variable
>>> await s3.set_session()  # doctest: +SKIP
# blocking version of set_session
>>> s3.connect(refresh=True)  # doctest: +SKIP
s3fs/core.py