Athena查询失败,boto3(S3位置无效)

2024-05-16 07:44:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在雅典娜中执行一个查询,但失败了。

代码:

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.

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

athena settings

查询运行正常。

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

Python:3.6.1。博特3:1.4.4


Tags: andtheto代码clientdbyours3
3条回答

或者尝试boto3.client('athena', region_name = '<region>')

遇到同样的问题,需要在客户机中指定S3存储桶。

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

因为它在使用控制台时工作,所以很可能bucket所在的区域与您在Boto3中使用的区域不同。在构造Boto3客户机时,请确保使用正确的区域(在控制台中工作的区域)。默认情况下,Boto3将使用凭据文件中配置的区域。

我必须在我的桶上加上“雅典娜-”前缀才能使它工作。例如,代替:

“s3:/我的桶/”

尝试:

“s3:/雅典娜我的桶”

相关问题 更多 >