Skip to content

Instantly share code, notes, and snippets.

@nsabharwal
Created September 18, 2019 03:49
Show Gist options
  • Save nsabharwal/5061353405510bcaa0e6c4f0408ff8d8 to your computer and use it in GitHub Desktop.
Save nsabharwal/5061353405510bcaa0e6c4f0408ff8d8 to your computer and use it in GitHub Desktop.
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