0

I'm currently trying to build a data pipeline from an AWS Athena database so my team can query information using Python. However, I'm running into an issue with insufficient permissions.

We are able to query the data in Tableau, but we wanted to integrate it into an app we are developing.

Here is the code we followed from PyAthena's documentation.

from pyathena import connect
import pandas as pd

conn = connect(aws_access_key_id='YOUR_ACCESS_KEY_ID',
               aws_secret_access_key='YOUR_SECRET_ACCESS_KEY',
               s3_staging_dir='s3://YOUR_S3_BUCKET/path/to/',
               region_name='us-west-2')
df = pd.read_sql("SELECT * FROM many_rows", conn)
print(df.head()) 

Here is the resulting error.

OperationalError: Insufficient permissions to execute the query.  User: arn:aws:iam::OUR_ADDRESS:user/USER is not authorized to perform: glue:GetTable on resource: arn:aws:glue:us-west-2:OUR_ADDRESS:table/default/OUR_DATABASE 

I'm guessing that this is an issue with IAM permissions on the Server side with respect to Amazon Glue. But I'm not sure how to resolve it.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
kpdebree
  • 11
  • 4
  • You need to add the permissions. How are you running the code? From lambda, instance, localhost? – Marcin Mar 06 '20 at 00:16
  • We're running it the code from a script on my laptop. We can connect from Tableau to the database on our the same device, but not query through PyAthena. – kpdebree Mar 06 '20 at 00:57
  • So have to check if IAM user you are using on your laptop has permissions to execute `glue:GetTable`. – Marcin Mar 06 '20 at 01:23
  • SOLVED: I found the error, it was on my end. I incorrectly implemented the SQL code to use the Database. The code needs SELECT * FROM database.table, instead of USE DB, then SELECT * FROM. – kpdebree Mar 06 '20 at 18:04

0 Answers0