Choose where query results are stored
A DuckDB workgroup uses managed query results by default. Optionally, you can configure the workgroup to store query results in your own Amazon S3 bucket (a customer managed bucket). Choose based on how you use the results:
-
To have Athena store, encrypt, and delete results for you, or to read results as Apache Arrow with
GetQueryResultStream, use managed query results. -
If your applications read result files directly from Amazon S3, for example with the
GetObjectAPI, or you need to keep results longer than 24 hours, use a customer managed bucket.
GetQueryResults returns the same values whichever option you choose.
The following table compares the two options.
| Feature | Managed query results (default) | Customer managed bucket |
|---|---|---|
| Result files that you can read in Amazon S3 | No. To create files with SQL, see Download and export query results. | Yes. Each query writes a .csv file and a .csv.metadata file. |
| Retention | 24 hours | Controlled by you, for example with Amazon S3 lifecycle rules. |
| Encryption | An AWS owned key (default) or a customer managed key in AWS KMS. | Server-side encryption with Amazon S3 managed keys (SSE-S3) or with AWS KMS keys (SSE-KMS). Client-side encryption (CSE-KMS) is not supported. |
GetQueryResults |
Supported | Supported |
GetQueryResultStream (Apache Arrow) |
Supported | Not supported |
| Download from the console | Up to 200 MB for each download. | The full result file. |
Use managed query results
New DuckDB workgroups use managed query results by default. Workgroups that you migrate from Athena engine version 3 keep their query result location. You don't need to create or manage a results bucket. Athena keeps each result for 24 hours. During that time, you can read the result as many times as you need, with GetQueryResults or GetQueryResultStream. After 24 hours, Athena deletes the result. To keep a result longer, write it to files or a table, as described in Download and export query results, or store results in your own bucket.
Managed query results are encrypted at rest. Choose one of the following options:
-
AWS owned key – The default. You don't manage the key, and you aren't charged for it.
-
Customer managed key – An AWS KMS key that you create and manage. Set the key on
ManagedQueryResultsConfiguration.EncryptionConfiguration.KmsKey. Athena encrypts each result with the key that the workgroup uses when the query runs. If you later change the key, Athena doesn't re-encrypt existing results.
If you use a customer managed key, the key policy must allow the encryption.athena.amazonaws.com service principal to use kms:Decrypt, kms:GenerateDataKey, and kms:DescribeKey.
The principal that runs the query and reads its results must also be allowed to use the key. Athena checks access to the key when you submit the query, and rejects the query if the key can't be used.
With managed query results, you can't access results as files in Amazon S3. To read results, use GetQueryResults or GetQueryResultStream. To create files, see Download and export query results.
Use a customer managed bucket
To store results in your own bucket, set the workgroup's query result location to that bucket. The principal that runs queries needs write access to the location. Principals that read results need read access to it. If you use SSE-KMS, both principals also need permission to use the AWS KMS key.
Query results in your bucket can be encrypted with SSE-S3 or SSE-KMS. CSE-KMS is not supported.
When you set an expected bucket owner, Athena verifies that the account owns the bucket when you save the workgroup. The only supported ACL option is BUCKET_OWNER_FULL_CONTROL.
S3 Access Grants are not supported for DuckDB query results.
Result settings in a query request
StartQueryExecution accepts a ResultConfiguration with OutputLocation, EncryptionConfiguration, ExpectedBucketOwner, and AclConfiguration. How Athena uses it depends on the workgroup:
-
If the workgroup uses managed query results, Athena rejects the request with the message
ManagedQueryResultsConfiguration and ResultConfiguration cannot be set together. -
If the workgroup uses a query result location, Athena uses the values from the request. If the workgroup has Override client-side settings turned on, the workgroup's value takes precedence for each setting that the workgroup defines.
The same rules apply to settings that a client sends for you, such as the OutputLocation connection parameter of the JDBC and ODBC drivers.
Result files in a customer managed bucket
Each query writes its files directly under the query result location. Files are named with the query execution ID.
| File | Name | Description |
|---|---|---|
| Result file | |
The result in CSV format, with a header row. Every statement type writes a CSV file, including SHOW, DESCRIBE, and EXPLAIN. |
| Metadata file | |
Column names and types in a binary format internal to Athena. Athena uses this file to return results with GetQueryResults. Don't delete or change it. |
To find the result file for a query, use the get-query-execution command and read ResultConfiguration.OutputLocation. Replace the example query execution ID with your own.
aws athena get-query-execution --query-execution-ida1b2c3d4-5678-90ab-cdef-EXAMPLE11111