AWS Data Wrangler - wr.athena.read_sql_query 不起作用

问题描述 投票:0回答:4

我开始使用 AWS Data Wrangler lib (https://aws-data-wrangler.readthedocs.io/en/stable/what.html

在 AWS Athena 上执行查询并在我的 AWS Glue python shell 作业中使用它们的结果。

我看到存在 wr.athena.read_sql_query 来获取我需要的内容。

这是我的代码:

import sys
import os
import awswrangler as wr

os.environ['AWS_DEFAULT_REGION'] = 'eu-west-1'
databases = wr.catalog.databases()
print(databases)

query='select count(*) from staging_dim_channel'
print(query)
df_res = wr.athena.read_sql_query(sql=query, database="lsk2-target")
print(df_res)
print(f'DataScannedInBytes:            {df_res.query_metadata["Statistics"]["DataScannedInBytes"]}')
print(f'TotalExecutionTimeInMillis:    {df_res.query_metadata["Statistics"]["TotalExecutionTimeInMillis"]}')
print(f'QueryQueueTimeInMillis:        {df_res.query_metadata["Statistics"]["QueryQueueTimeInMillis"]}')
print(f'QueryPlanningTimeInMillis:     {df_res.query_metadata["Statistics"]["QueryPlanningTimeInMillis"]}')
print(f'ServiceProcessingTimeInMillis: {df_res.query_metadata["Statistics"]["ServiceProcessingTimeInMillis"]}')

我毫无问题地检索了数据库列表(包括 lsk2-target),但 read_sql_query 出现错误,我收到:

WaiterError: Waiter BucketExists failed: Max attempts exceeded

请问您能帮助我理解我错在哪里吗? 谢谢!

amazon-web-services aws-glue amazon-athena
4个回答
0
投票

修复了类似的问题,解决方案是确保使用的 IAM 角色具有创建表所需的 Athena 权限。由于此 API 默认运行在

ctas_approach=True
.

参考。 文档

此外,一旦问题解决,请确保 IAM 角色也有权删除在 S3 中创建的文件


0
投票

这可能是 IAM 问题(即使按照所述使用 boto3 解决了问题)。例如,请参阅:https://stackoverflow.com/a/76800662/10884780


0
投票

我使用 Boto3 for Athena 解决了问题


-1
投票

您是否拥有正确的 IAM 权限来读取执行查询?我敢打赌这是一个 IAM 问题。

我猜你已经设置了你的凭据:

[default]
aws_access_key_id = your_access_key_id
aws_secret_access_key = your_secret_access_key
© www.soinside.com 2019 - 2024. All rights reserved.