簡體   English   中英

Athena 上的 AWS lambda 查詢不返回任何內容

[英]AWS lambda query on Athena returns nothing

我正在嘗試制作一個 Python 腳本,其中包含對我的 Athena 數據庫的查詢(我創建了一個 Amazon S3 存儲桶作為輸出)。 我看到了一些基礎教程,並得到了以下代碼:

import json
import boto3
import time

def lambda_handler(event, context):
    client = boto3.client('athena')

    QueryResponse = client.start_query_execution(
        QueryString = "SELECT id FROM table;",
        QueryExecutionContext = {
            'Database' : 'raw'
        },
        ResultConfiguration = {
            'OutputLocation' : 's3://mybucket/'
       }
    )


    #Oberserve results : 
    queryId = QueryResponse['QueryExecutionId']
    time.sleep(10)

    results = client.get_query_results(QueryExecutionId = queryId)
    for row in results['ResultSet']['Rows']:
        print(row)

此代碼應該打印查詢檢索到的數據。 但是當我運行它時,我有這個錯誤消息:

    Response
{
  "errorMessage": "An error occurred (InvalidRequestException) when calling the 
GetQueryResults operation: Query did not finish successfully. Final query state: FAILED",
  "errorType": "InvalidRequestException",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 23, in lambda_handler\n    results = 
client.get_query_results(QueryExecutionId = queryId)\n",
    "  File \"/var/runtime/botocore/client.py\", line 357, in _api_call\n    return 
self._make_api_call(operation_name, kwargs)\n",
    "  File \"/var/runtime/botocore/client.py\", line 676, in _make_api_call\n    raise 
error_class(parsed_response, operation_name)\n"
  ]
}

我嘗試在 Athena 上運行查詢以查看它是否正在返回數據並且查詢工作正常。 我還嘗試在沒有部分編寫器的情況下運行代碼:'#Observe results:',而且我的代碼似乎沒有返回任何內容,因為響應只是'null'。 我不明白為什么或從哪里來的問題。 關於我應該做什么的任何想法或建議?

感謝您的幫助。

好的,我剛剛檢查了 Athena 中的歷史記錄,這實際上是 Amazon S3 權限問題。 我確實添加了我在 S3 上使用權限的角色,它工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM