View a markdown version of this page

Run your first query with the AWS CLI - Amazon Athena

Run your first query with the AWS CLI

This quickstart walks you through running your first DuckDB query with the AWS Command Line Interface (AWS CLI). This walkthrough takes you from confirming the engine is available to query results against your own data.

Note

You are charged for the queries that you run in this walkthrough. To avoid ongoing charges, complete the cleanup step at the end.

  1. Confirm the engine is available. Run aws athena list-engine-versions --region your-region and check that DuckDB appears.

  2. Create a workgroup that uses DuckDB. See Working with DuckDB workgroups.

  3. Query your own data. Register a table over data in Amazon S3 and query it, one statement per request. See Get started.

  4. Wait for the query to succeed. Poll GetQueryExecution until Status.State is SUCCEEDED.

  5. Read the results with GetQueryResults, or in the console query editor.

  6. Review each query's resource usage with GetQueryExecution. See Review usage with GetQueryExecution.

  7. Clean up. To avoid incurring additional charges, delete the workgroup and any other resources that you created in this walkthrough.

The following AWS CLI commands run the walkthrough end to end. In each command, replace your-region with your AWS Region, query-execution-id with the ID returned by start-query-execution, and file-name.arrow with the output file name.

The following AWS CLI command creates a DuckDB workgroup with "DuckDB" specified as EngineVersion. If the Athena service-linked role doesn't exist in your account yet, the principal that runs this command needs permission for iam:CreateServiceLinkedRole. For more information, see Athena service-linked role:

aws athena create-work-group \ --name my-duckdb-workgroup \ --configuration '{ "EngineVersion": { "SelectedEngineVersion": "DuckDB" } }' \ --region your-region

To run a single query on DuckDB without a DuckDB workgroup, override the engine in start-query-execution. For more information, see Override the engine for a single query.

Note

You can run DuckDB queries against an Athena engine version 3 workgroup by specifying an engine version. For more details, see Override the engine for a single query.

The following AWS CLI command starts a query execution as you would for Athena engine version 3:

aws athena start-query-execution \ --query-string "SELECT * FROM my_database.my_table LIMIT 10" \ --work-group my-duckdb-workgroup \ --region your-region

The following AWS CLI commands get the query execution status and the query execution results:

aws athena get-query-execution --query-execution-id "query-execution-id" --region your-region aws athena get-query-results --query-execution-id "query-execution-id" --region your-region aws athena get-query-result-stream --query-execution-id "query-execution-id" --region your-region file-name.arrow

To avoid incurring additional charges, the following AWS CLI command deletes the workgroup when you finish the walkthrough:

aws athena delete-work-group \ --work-group my-duckdb-workgroup \ --region your-region