Run your first query with the Amazon CLI
This quickstart walks you through running your first DuckDB query with the Amazon Command Line Interface (Amazon CLI). This walkthrough takes you from confirming the engine is available to query results against your own data.
You are charged for the queries that you run in this walkthrough. To avoid ongoing charges, complete the cleanup step at the end.
-
Confirm the engine is available. Run
aws athena list-engine-versions --regionand check thatyour-regionDuckDBappears. -
Create a workgroup that uses DuckDB. See Working with DuckDB workgroups.
-
Query your own data. Register a table over data in Amazon S3 and query it, one statement per request. See Get started.
-
Wait for the query to succeed. Poll
GetQueryExecutionuntilStatus.StateisSUCCEEDED. -
Read the results with
GetQueryResults, or in the console query editor. -
Review each query's resource usage with GetQueryExecution. See Review usage with GetQueryExecution.
-
Clean up. To avoid incurring additional charges, delete the workgroup and any other resources that you created in this walkthrough.
The following Amazon CLI commands run the walkthrough end to end. In each command, replace your-region with your Amazon Region, query-execution-id with the ID returned by start-query-execution, and file-name.arrow with the output file name.
The following Amazon 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" } }' \ --regionyour-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.
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 Amazon 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 \ --regionyour-region
The following Amazon CLI commands get the query execution status and the query execution results:
aws athena get-query-execution --query-execution-id "query-execution-id" --regionyour-regionaws athena get-query-results --query-execution-id "query-execution-id" --regionyour-regionaws athena get-query-result-stream --query-execution-id "query-execution-id" --regionyour-regionfile-name.arrow
To avoid incurring additional charges, the following Amazon CLI command deletes the workgroup when you finish the walkthrough:
aws athena delete-work-group \ --work-group my-duckdb-workgroup \ --regionyour-region