Skip to content

Instantly share code, notes, and snippets.

@ksdkamesh99
Created May 5, 2021 11:15
Show Gist options
  • Save ksdkamesh99/3d655c0b4230fe61a5eb8d571a276cda to your computer and use it in GitHub Desktop.
Save ksdkamesh99/3d655c0b4230fe61a5eb8d571a276cda to your computer and use it in GitHub Desktop.
AWS Athena Query Via Lambda
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