Copy Codeimport boto3
import json
def lambda_handler(event, context):
client = boto3.client('athena')
response = client.start_query_execution(
QueryString='SELECT * FROM my_table WHERE condition',
QueryExecutionContext={
'Database': 'my_database'
},
ResultConfiguration={
'OutputLocation': 's3://my-bucket/query-results/'
}
)
return response
Copy Code{
"source": ["aws.athena"],
"detail-type": ["Athena Query State Change"],
"detail": {
"query-state": ["SUCCEEDED"]
}
}
Copy Code{
"TopicArn": "arn:aws:sns:us-east-1:123456789012:MyTopic",
"Protocol": "email",
"Endpoint": "[email protected]"
}
Copy Codeimport boto3
import json
def lambda_handler(event, context):
client = boto3.client('athena')
response = client.start_query_execution(
QueryString='SELECT * FROM my_table WHERE condition',
QueryExecutionContext={
'Database': 'my_database'
},
ResultConfiguration={
'OutputLocation': 's3://my-bucket/query-results/'
}
)
if response['QueryExecution']['Status']['State'] == 'SUCCEEDED':
sns = boto3.client('sns')
sns.publish(
TopicArn='arn:aws:sns:us-east-1:123456789012:MyTopic',
Message='Alert: Query results meet criteria',
Subject='Athena Alert'
)
return response