2 Answers
- Newest
- Most votes
- Most comments
1
I generally use the following steps.
- get all query ID's
- get the query details for each query ID
- check if its the right one & do something
Code:
Get Athena client/object
client = boto3.client('athena')
# Get all the saved queries in Athena
response = client.list_named_queries()
# Get the named query IDs from the response
named_query_IDs = response['NamedQueryIds']
# Go through all the query ID, to find the delete & create queries we need to run
for query_ID in named_query_IDs:
# Get all the details of a named query using its ID
named_query = client.get_named_query(
NamedQueryId=query_ID
)
# Get the query string & query name of the query
querystring = named_query['NamedQuery']['QueryString']
queryname = named_query['NamedQuery']['Name']
# If its a create query, add it to the list of create queries
# We also replace the '/subfolder' string in the query with the folder structure for the current month
if 'create_linked_' in queryname:
new_query = querystring.replace('/subfolder', currentmonth)
create_query_strings.append(new_query)
# If its a delete query, add it to the list of delete queries to execute later
if 'delete_linked_' in queryname:
delete_query_strings.append(querystring)
1
Please check out the section from ** AWS Well-Architected Labs** ,
CREATE LAMBDA FUNCTION TO RUN THE SAVED QUERIES
answered 2 years ago
Relevant content
- asked a year ago
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago