I am trying to execute an AWS Athena query in my Jupyter notebook and also retrieve the results using Boto3.
I first ran this to execute my query:
response1 = client.start_query_execution(
QueryString= "SELECT date from my data_table LIMIT 1;",
QueryExecutionContext={
'Database': 'my_database',
'Catalog': 'AwsDataCatalog'
},
ResultConfiguration={
'OutputLocation': 's3://XXX/YYY/'
}
)
The resultant output of the response is:
{'QueryExecutionId': 'abcd123456',
'ResponseMetadata': {'RequestId': 'efgh123456',
'HTTPStatusCode': 200,
'HTTPHeaders': {'content-type': 'application/x-amz-json-1.1',
'date': 'Mon, 05 Jul 2021 06:38:15 GMT',
'x-amzn-requestid': 'ijklmn123456',
'content-length': '59',
'connection': 'keep-alive'},
'RetryAttempts': 0}}
Next, I wanted to retrieve the results using the QueryExecutionId which is 'abcd123456' obtained above as shown below:
response2 = client.get_query_results(
QueryExecutionId = 'abcd123456',
MaxResults = 123
)
However, it throws me this error:
InvalidRequestException: An error occurred (InvalidRequestException) when calling the GetQueryResults operation: Query did not finish successfully. Final query state: FAILED
I wonder why does it say final query state is 'FAILED' when the HTTPStatusCode of the start_query_execution is 200. I did refer to this link (InvalidRequestException) when calling the GetQueryResults..... Querying Athena From Lambda Python.... Cannot Read Results but I couldn't solve my problem.
Would greatly appreciate if someone could help me with this!
Turns out I can run the query and obtain the results when I changed my s3 output location. I guess I had limited permission to the previous s3 bucket path I used.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments