Simple demo application illustrating how to run Athena queries over S3 files locally, using LocalStack.
- LocalStack
- Docker
- Node.js /
npm
make
To install the dependencies:
make install
Make sure that LocalStack is started:
LOCALSTACK_AUTH_TOKEN=... DEBUG=1 localstack start
Start the app locally and run the Athena test queries:
make run
The demo script performs the following actions:
- Create an S3 bucket and upload test data (CSV files with person details) to the bucket
- Run queries to create the table metadata in Athena
- Running a simple query over the test file - querying the number of users by gender (male/female)
- Downloading the query results from the S3 results bucket
You should see something similar to the following log output in the terminal:
$ ./run.sh
Uploading test data to S3...
make_bucket: athena-test
upload: data/data.csv to s3://athena-test/data/data.csv
Running queries to create database and table definitions...
NOTE: This can take a very long time (several minutes) as the system is initializing
Waiting for completion status of query cda0572a: RUNNING
Waiting for completion status of query cda0572a: RUNNING
Waiting for completion status of query cda0572a: RUNNING
...
Waiting for completion status of query cda0572a: SUCCEEDED
Starting SELECT query over data in S3. Query ID: 8a19e3a3
S3 query output location: s3://athena-test/results/Unsaved/2020/02/18/8a19e3a3
Waiting for query results to become available in S3 (this can take some time)
download: s3://athena-test/results/Unsaved/2020/02/18/8a19e3a3/results.csv to /tmp/8a19e3a3.results.csv
Query result downloaded from S3:
Male,49
Female,51
This code is available under the Apache 2.0 license.