Created
May 5, 2021 11:15
-
-
Save ksdkamesh99/3d655c0b4230fe61a5eb8d571a276cda to your computer and use it in GitHub Desktop.
AWS Athena Query Via Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import time | |
import boto3 | |
client=boto3.client("athena") | |
def lambda_handler(event, context): | |
QUERY="SELECT * from data order by age desc limit 10;" | |
DATABASE="data" | |
OutputPath="s3://sri-reco-demo/Athena/" | |
response=client.start_query_execution( | |
QueryString=QUERY, | |
QueryExecutionContext={ | |
'Database': DATABASE | |
}, | |
ResultConfiguration={ | |
'OutputLocation': OutputPath | |
}); | |
query_id=response['QueryExecutionId'] | |
time.sleep(5) | |
query_stats=client.get_query_execution(QueryExecutionId=query_id) | |
Status=query_stats['QueryExecution']['Status']['State'] | |
return { | |
'statusCode': 200, | |
'body': json.dumps(Status) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment