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

Bug: Passing Session to Connection, doesn't update client args for S3fs #375

Open
aaronclong opened this issue Oct 27, 2022 · 3 comments
Open

Comments

@aaronclong
Copy link

aaronclong commented Oct 27, 2022

Currently, when a session is passed, the client args aren't updated to reflect the session's credentials.
This is important for the PandasCursor because it passes the client args to s3fs to grab the files. It can create access issues and get failures.

@aaronclong
Copy link
Author

A possible work around is to set these credentials as kwargs for now, but PyAthena could also handle this in the future.

if session: 
     self._session = session 
     creds = session.get_credentials()
     cred_value = creds.get_frozen_credentials()
     self._kwargs.update(
           {
               "aws_access_key_id": cred_value.access_key,
                "aws_secret_access_key": cred_value.secret_key,
                "aws_session_token": cred_value.token
             }
      )

@laughingman7743
Copy link
Owner

Thank you. The workaround implementation looks good, but it would be nice if the Session object could be passed to s3fs.
https://github.com/fsspec/s3fs/blob/main/s3fs/core.py#L271
It seems to be expected that the AioSession object can be passed though.
https://github.com/aio-libs/aiobotocore/blob/master/aiobotocore/session.py#L33

@laughingman7743
Copy link
Owner

laughingman7743 commented Nov 17, 2022

It is difficult to convert a botocore Session object to an AioSession.
I have tried the following fix, but I am not sure if this fix is correct for me.
#378

    def __s3_file_system(self):
        from s3fs import S3FileSystem

        creds = self.connection.session.get_credentials().get_frozen_credentials()
        client_kwargs = self.connection._client_kwargs
        client_kwargs.update(
            {
                "aws_access_key_id": creds.access_key,
                "aws_secret_access_key": creds.secret_key,
                "aws_session_token": creds.token,
            }
        )
        return S3FileSystem(
            profile=self.connection.profile_name,
            client_kwargs={
                "region_name": self.connection.region_name,
                **client_kwargs,
            },
        )

laughingman7743 added a commit that referenced this issue Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants