Skip to content

Instantly share code, notes, and snippets.

@tomodian
Created March 27, 2017 08:46
Show Gist options
  • Save tomodian/909c5e2190ab2fe8785c1dfcce711335 to your computer and use it in GitHub Desktop.
Save tomodian/909c5e2190ab2fe8785c1dfcce711335 to your computer and use it in GitHub Desktop.
Athena on Python Demo
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()
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"]
PyAthenaJDBC==1.0.6
#!/bin/sh
tail -f /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment