

# 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. 

1.  **Create a workgroup** that uses DuckDB. See [Working with DuckDB workgroups](duckdb-workgroups.md). 

1.  **Query your own data. Register a table over data in Amazon S3 and query it, one statement per request.** See [Get started](getting-started.md). 

1.  **Wait for the query to succeed.** Poll `GetQueryExecution` until `Status.State` is `SUCCEEDED`. 

1.  **Read the results** with `GetQueryResults`, or in the console query editor. 

1.  **Review each query's resource usage with GetQueryExecution.** See [Review usage with GetQueryExecution](duckdb-usage-and-costs.md#athena-duckdb-usage-and-costs-review-usage-with-getqueryexecution). 

1.  **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](duckdb-permissions.md#athena-duckdb-permissions-service-linked-role): 

```bash
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](duckdb-engine-override.md). 

**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](duckdb-engine-override.md).

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

```bash
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: 

```bash
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: 

```bash
aws athena delete-work-group \
  --work-group my-duckdb-workgroup \
  --region {{your-region}}
```