2017-07-25 79 views
0

我想在雅典娜執行查詢,但它失敗。雅典娜查詢失敗與boto3(S3位置無效)

代碼:

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。 Boto3:1.4.4

回答

1

提供用於保存查詢結果的S3位置無效。 請檢查您的S3位置是否正確,並且位於同一地區,然後重試。

由於它在您使用控制檯時有效,因此該桶可能與您在Boto3中使用的區域不同。在構建Boto3客戶端時,請確保使用正確的區域(在控制檯中工作的區域)。默認情況下,Boto3將使用憑證文件中配置的區域。

1

或者嘗試boto3.client('athena', region_name = '<region>')

遇到同樣的問題,並指定在客戶端的S3存儲需要。

0

我不得不爲我的存儲桶添加'athena-'前綴才能使其工作。例如,在代替:

「S3://我的桶/」

嘗試:

「S3://雅典娜我的桶/」