Pandas (v1.0.5) use s3fs
library to connect with AWS S3 and read data. By default, s3fs uses the credentials found in ~/.aws/credentials
file in default
profile. How do I specify which profile should pandas use while reading a CSV from S3?
Eg.
s3_path = 's3://mybucket/myfile.csv'
df = pd.read_csv(s3_path)
$ cat ~/.aws/credentials
[default]
aws_access_key_id = ABCD
aws_secret_access_key = XXXX
[profile2]
aws_access_key_id = PQRS
aws_secret_access_key = YYYY
[profile3]
aws_access_key_id = XYZW
aws_secret_access_key = ZZZZ
Edit :
Current hack/working solution :
import botocore
import s3fs
session = botocore.session.Session(profile='profile2')
s3 = s3fs.core.S3FileSystem(anon=False, session=session)
df = pd.read_csv( s3.open(path_to_s3_csv) )
The only issue with above solution is you need to import 2 different libraries and instantiate 2 objects. Keeping the question open to see if there is another cleaner/simple method.