Hi,
How can I use the code below with AWS profile_name in order to read parquet files from S3?
df = wr.s3.read_parquet(filepath, dataset=True)
Thanks
Hi @nivcoh!
You have three alternatives:
my_session = boto3.Session(profile_name ="MY_PROFILE_NAME")
wr.s3.read_parquet(filepath, dataset=True, boto3_session=my_session)
boto3.setup_default_session(profile_name ="MY_PROFILE_NAME")
wr.s3.read_parquet(filepath, dataset=True)
$export AWS_PROFILE=MY_PROFILE_NAME
wr.s3.read_parquet(filepath, dataset=True)
Thank you @igorborgest , I need a general solution so option 1 will be the best fit.
Unfortunately, it's still not working for some reason:
import awswrangler as wr
import pandas as pd
import boto3
new_session = boto3.Session(profile_name='myProfile', region_name='us-east-1')
filepath = 's3://my_bucket/myfile.parquet'
df = wr.s3.read_parquet(filepath, dataset=True, boto3_session=new_session)
I get:
_ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden_
Now seems it is just lack of permission. Are you sure you have privileges in this bucket?
You can also test the same credentials through AWS CLI:
aws s3 ls s3://your_bucket/ --profile YOUR_PROFILE
This is becoming an interesting case:
InvalidArgumentValue: Object s3://my_backet/my_testFile.parquet is not under the root path (s3://my_backet/my_testFile.parquet/).
-I should mention that the original file I'm trying to open (using the example code above), was written from a different remote environment (EC2) into this bucket, and I'm trying to open it from my local env but it seem to be locked or something.
Now, I don't see any reason why it should matter if the file was written
Oh this error now is different, if you are trying to read a single file you should pass dataset=False.
or simply:
wr.s3.read_parquet(filepath)
@igorborgest 馃憤
This solves the issue and I can load the parquet file I created.
As for the original file (which is created by a remote process on an EC2) I keep getting this error:
_ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden_
Is it a privileges issue?
Is it a privileges issue?
Yes.
Ok, so my guess is that it is a ACL issue. So basically the EC2 should add ACL permissions for the bucket owner during the upload.
good guessing!
so using cli it will be something like:
aws s3api put-object-acl --bucket awsexamplebucket --key my_file.parquet --acl bucket-owner-full-control
is there a more pythonic way? or just to pass such one?
@nivcoh you can also do the same with boto3.
Yap, I figured this out 馃憤
Thank you for the kind help :)