

# クエリ履歴を 45 日間よりも長く保持する
<a name="querying-keeping-query-history"></a>

クエリ履歴を 45 日より長く保持する場合は、クエリ履歴を取得して、Amazon S3 などのデータストアに履歴を保存できます。このプロセスを自動化するには、Athena および Amazon S3 の API アクションと CLI コマンドを使用できます。以下の手順は、これらのステップをまとめたものです。

**クエリ履歴をプログラムで取得して保存するには**

1. Athena の [ListQueryExecutions](https://docs.aws.amazon.com/athena/latest/APIReference/API_ListQueryExecutions.html) API アクション、または [list-query-executions](https://docs.aws.amazon.com/cli/latest/reference/athena/list-query-executions.html) CLI コマンドを使用して、クエリ ID を取得します。

1. Athena の [GetQueryExecution](https://docs.aws.amazon.com/athena/latest/APIReference/API_GetQueryExecution.html) API アクション、または [get-query-execution](https://docs.aws.amazon.com/cli/latest/reference/athena/get-query-execution.html) CLI コマンドを使用して、ID に基づいた各クエリに関する情報を取得します。

1. Simple Storage Service (Amazon S3) の [PutObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html) API アクション、または [put-object](https://docs.aws.amazon.com/cli/latest/reference/s3api/put-object.html) CLI コマンドを使用して、その情報を Amazon S3 に保存します。