Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Athena script
import subprocess,json,sys
def runAndGet(cmd,parse=False):
print(cmd)
dummy=raw_input()
try:
data = subprocess.check_output(cmd, shell=True)
except:
sys.exit(0)
print(data)
dummy=raw_input()
if parse:
#get the output
jsonStuff=json.loads(data)
qid=str(jsonStuff['QueryExecutionId'])
return qid
def runWithProcess(cmd,qid):
cmd = cmd+'"'+qid+'"'
runAndGet(cmd)
#first run step 1
cmd ='aws athena start-query-execution --query-string "SELECT * FROM customer_data.customer_data_april LIMIT 5;" --result-configuration "OutputLocation=s3://priv-demo-customer-athena-test/output/"'
cmd2 = 'aws athena get-query-execution --query-execution-id '
cmd3 = 'aws athena get-query-results --query-execution-id '
qid = runAndGet(cmd,True)
runWithProcess(cmd2,qid)
runWithProcess(cmd3,qid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.