Skip to content

BUG: Read from S3 fails after assuming an AWS IAM role #39325

@justinessert

Description

@justinessert
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

import pandas as pd

assume_iam_role(role)
pd.read_csv(filepath)

Problem description

Hey all, I am having an issue where after assuming an AWS IAM role, I still get a forbidden error when running pd.read_csv. This error only happens in a Jupyter notebook. When just running a Python file, everything works (maybe related to the notebook kernel?).

Additionally, if I re-import Pandas after I assume the IAM role, then I am able to read from AWS without error.

Unfortunately, I have to assume my IAM role through a specific command that is internal to my company, so I am unable to share exactly how that part is happening (though I think it is mostly just calling the AWS CLI).

Could someone help me understand why this is happening and/or suggest a better way to handle this issue rather than re-importing pandas? I assume something is happening in the __init__.py, but after looking through this repo, I am unsure how the read from S3 stuff is being handled at all.

Expected Output

pd.read_csv works without error after assuming an IAM role.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 9d598a5
python : 3.7.9.final.0
python-bits : 64
OS : Linux
OS-release : 4.14.209-160.339.amzn2.x86_64
Version : #1 SMP Wed Dec 16 22:44:04 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.1
numpy : 1.19.5
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.3.3.post20210118
Cython : None
pytest : 6.2.1
hypothesis : None
sphinx : 3.4.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.5
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : 1.0.1
pyxlsb : None
s3fs : 0.5.2
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO NetworkLocal or Cloud (AWS, GCS, etc.) IO IssuesNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions