Skip to content

Instantly share code, notes, and snippets.

@davidonlaptop
Created March 22, 2022 20:01
Show Gist options
  • Save davidonlaptop/69968240220ef5d3442c5757c8d484a1 to your computer and use it in GitHub Desktop.
Save davidonlaptop/69968240220ef5d3442c5757c8d484a1 to your computer and use it in GitHub Desktop.
Generate Athena database documentation with SchemaSpy
description=AWS Athena
type=athena
driver=com.simba.athena.jdbc42.Driver
connectionSpec=jdbc:awsathena://athena.<region>.amazonaws.com:443;S3OutputLocation=<S3OutputLocation>
# eg: region=ca-central-1
tableTypes=TABLES,TABLE,MANAGED_TABLE,EXTERNAL_TABLE
#!/bin/bash
# for configuration / customization details:
# see http://schemaspy.readthedocs.io/en/latest/configuration.html#databasetype
# see https://hub.docker.com/r/schemaspy/schemaspy/
# see https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC-2.0.27.1000/doc/Simba+Athena+JDBC+Connector+Install+and+Configuration+Guide.pdf
# see https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html
# see https://blog.jetbrains.com/datagrip/2018/05/25/using-aws-athena-from-intellij-based-ide/
#
echo "*** Reading AWS access key and secrets..."
AWS_KEY=`awk -F "=" '/^aws_access_key_id/ {gsub(/[ \t]/, "", $2); print $2}' ~/.aws/credentials`
AWS_SECRET=`awk -F "=" '/^aws_secret_access_key/ {gsub(/[ \t]/, "", $2); print $2}' ~/.aws/credentials`
echo "*** Launching schema spy"
ATHENA_REGION=ca-central-1
S3_OUTPUT_LOCATION="s3://aws-athena-query-results-638085509885-ca-central-1/"
SCHEMA=mvp-flink-data
SCHEMASPY_OPTIONS="-t athena -norows -region $ATHENA_REGION -S3OutputLocation $S3_OUTPUT_LOCATION -db AwsDataCatalog -s $SCHEMA"
mkdir -p doc/athena
docker run --rm -it \
-v $HOME/opt:/drivers \
-v $HOME/opt/athena.properties:/athena.properties \
-v `pwd`/doc/athena:/output \
schemaspy/schemaspy \
$SCHEMASPY_OPTIONS \
-u $AWS_KEY -p $AWS_SECRET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment