【发布时间】:2021-06-01 14:41:48
【问题描述】:
我正在尝试制作一个 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 中主要工作组的历史记录,UI 会告诉您查询失败的原因是什么?
-
表名表?
-
我知道了:您的查询有以下错误:com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code:拒绝访问;
-
这是否意味着我没有具有正确访问权限的角色?
标签: python mysql amazon-web-services aws-lambda boto3