The python code below can fetch data from a pre-configured athena table when it is run on local computer. But it automatically creates an S3 bucket to store temporary tables and metadata. The automatically created bucket name looks like aws-athena-query-results-<account_id>-{aws-region>
. Is there a way to specify awswrangler
to use another S3 location?
import awswrangler as wr db_name = "test_db" table_name = "test_table" query = f"SELECT * FROM {db_name}.{table_name}" df = wr.athena.read_sql_query(sql=query, database=db_name)
31 Answer
Use s3_output
for setting custom output path per query as shown below.
# Query Athena using the wrangler library query = "SELECT * FROM my_table LIMIT 100" df = wr.athena.read_sql_query(query, database="my_database", s3_output=S3_OUTPUT_LOCATION)
There could be some exception like the one raised in this ticket, User specified s3_output not handled correctly in athena.read_sql_query with unload_approach=True
Unfortunately there is no way as of now to specify it as part of wrangler global config.
ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobm5tY2qGdYGOoaawZaSkerS8xJygn7FdqbWmecuompqsmaS7brvFZpitoJWjrm691J6psmWimsC2uNOsZLCglaN6tr%2FIp55mmaeoxLOtzaCjnqo%3D