Created
March 7, 2024 13:29
-
-
Save KamranBiglari/1c462203387094b1c99e5587d51b3e1a to your computer and use it in GitHub Desktop.
AWSCli: start athena query execution from file
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
| SELECT * FROM "${Table}" WHERE id='${Id}' |
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/bash | |
| Database=DATABASE_NAME | |
| OutputLocation=s3://S3_BUCKET/FOLDER/ | |
| Table=TABLE_NAME | |
| Id=1 | |
| Sql=`cat athena-query.tmpl.sql | Table=$table id=$Id envsubst` | |
| QueryExecutionId=`aws athena start-query-execution \ | |
| --query-string "$Sql" \ | |
| --query-execution-context Database=${Database} \ | |
| --result-configuration OutputLocation=${OutputLocation} \ | |
| --output json | jq -r .QueryExecutionId` | |
| echo "QueryExecutionId: $QueryExecutionId" | |
| aws s3 cp ${OutputLocation/${QueryExecutionId}.csv . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment