雅典娜查询失败,并出现boto3(S3位置无效)

Die*_*cic 1 python amazon-s3 boto3 amazon-athena

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

码:

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

但这引发了以下异常:

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.
Run Code Online (Sandbox Code Playgroud)

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

雅典娜设置

查询运行正常。

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

Python:3.6.1。Boto3:1.4.4

hel*_*loV 8

编辑:正如 Justin 所建议的,AWS 后来通过向athena存储桶添加前缀来增加对 Athena 的支持。请为他的回答点赞。


接受的答案

提供的用于保存查询结果的 S3 位置无效。请检查您的 S3 位置是否正确且在同一地区,然后重试。

由于它在您使用控制台时工作,因此存储桶可能与您在Boto3. 确保在构建Boto3客户端时使用正确的区域(在控制台中工作的区域)。默认情况下,Boto3将使用凭据文件中配置的区域。


Jus*_*itz 5

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

“ s3:// my-bucket /”

尝试:

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

  • 有谁知道为什么会这样,或者有解释该解决方案的 AWS 文档的链接吗? (3认同)