![](/img/trans.png)
[英]Run aws Athena query by Lambda: error name 'response' is not defined
[英]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.