Skip to main content
 首页 » 编程设计

python之Athena 查询因 boto3 而失败(S3 位置无效)

2025年05月04日10jackei

我尝试在 Athena 中执行查询,但失败了。

代码:

client.start_query_execution(QueryString="CREATE DATABASE IF NOT EXISTS db;", 
                           QueryExecutionContext={'Database': 'db'}, 
                           ResultConfiguration={ 
                                     'OutputLocation': "s3://my-bucket/", 
                                     'EncryptionConfiguration': { 
                                             'EncryptionOption': 'SSE-S3' 
                                             } 
                                     }) 

但它引发了以下异常:

botocore.errorfactory.InvalidRequestException: An error occurred (InvalidRequestException)  
when calling the StartQueryExecution operation: The S3 location provided to save your  
query results is invalid. Please check your S3 location is correct and is in the same  
region and try again. If you continue to see the issue, contact customer support  
for further assistance. 

但是,如果我转到 Athena 控制台,转到“设置”并输入相同的 S3 位置(例如):

查询运行良好。

我的代码有什么问题?我已经成功地使用了其他几个服务(例如 S3)的 API,但是在这个服务中我相信我传递了一些不正确的参数。谢谢。

python :3.6.1。 Boto3:1.4.4

请您参考如下方法:

我必须向我的存储桶添加“athena-”前缀才能使其正常工作。例如,代替:

“s3://我的桶/”

尝试:

“s3://athena-my-bucket/”