Created
March 27, 2017 08:46
-
-
Save tomodian/909c5e2190ab2fe8785c1dfcce711335 to your computer and use it in GitHub Desktop.
Athena on Python Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pyathenajdbc as athena | |
conn = athena.connect(access_key=os.environ['AWS_ACCESS_KEY_ID'], | |
secret_key=os.environ['AWS_SECRET_ACCESS_KEY'], | |
s3_staging_dir='s3://aws-athena-query-results-123456789012345-us-west-2/', | |
region_name=os.environ['AWS_REGION']) | |
try: | |
with conn.cursor() as cursor: | |
cursor.execute(""" | |
SELECT | |
COUNT(created_at) | |
FROM | |
sampledb.events | |
WHERE | |
dt > '2017-03-02' AND dt < '2017-03-04' | |
LIMIT 1000 | |
""") | |
print(cursor) | |
print(cursor.description) | |
print(cursor.fetchall()) | |
finally: | |
conn.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM openjdk:8u121-jre | |
WORKDIR /tmp | |
RUN echo "Install OS dependencies.." && \ | |
apt-get update && \ | |
apt-get -y install python python-dev python-pip && \ | |
echo "Fixing pip packaging with manual update.." && \ | |
apt-get purge -y python-pip && \ | |
wget https://bootstrap.pypa.io/get-pip.py && \ | |
python ./get-pip.py && \ | |
apt-get install python-pip | |
COPY requirements.txt . | |
RUN echo "Install app dependencies.." && \ | |
pip install -r requirements.txt | |
WORKDIR /athena | |
COPY run.sh / | |
CMD ["/run.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PyAthenaJDBC==1.0.6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
tail -f /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment