I need to connect to Athena using Python.
The code used is as follows:
import pyathena
import pandas as pd
athena_conn = pyathena.connect(access_key,
secret_key,
s3_staging_dir,
region_name)
df = pd.read_sql("SELECT * FROM db.tableLIMIT 10", athena_conn)
df.head(5)
I, personally don't have access to Athena with my AWS, hence I'm borrowing the access_key and secret_access_key
from my colleague, who has access to Athena.
I get the following error while running the code :
An error occurred (AccessDeniedException) when calling the StartQueryExecution operation:
User: arn:aws:iam::xxxxx:user/xxxx is not authorized to perform: athena:StartQueryExecution on resource:
arn:aws:athena:us-east-1:xxxx:workgroup/primary because no identity-based policy allows the
athena:StartQueryExecution action
unable to rollback
Is it because my account doesn't have access to Athena?
From pyathena · PyPI documentation:
Note that each parameter is specified with a name
aws_access_key_id="YOUR_ACCESS_KEY_ID", rather than merely being positional. It might be that you need to specify the name of each parameter when passing them to the function.Also, make sure the provided credentials are associated with an IAM User that has permission to use Amazon Athena AND has permission to access the underlying data in Amazon S3.