

# Resolver クエリログ用のテーブルを作成する
<a name="querying-r53-resolver-logs-creating-the-table"></a>

Athena コンソールのクエリエディタを使用して、Route 53 Resolver クエリログ用のテーブルを作成してクエリできます。

**Route 53 Resolver クエリログ用の Athena テーブルを作成してクエリする**

1. [https://console.aws.amazon.com/athena/](https://console.aws.amazon.com/athena/home) で Athena コンソールを開きます。

1. Athena クエリエディタに以下の `CREATE TABLE` ステートメントを入力します。`LOCATION` 句の値を、Simple Storage Service (Amazon S3) の Resolver ログの場所に対応する値に置き換えます。

   ```
   CREATE EXTERNAL TABLE r53_rlogs (
     version string,
     account_id string,
     region string,
     vpc_id string,
     query_timestamp string,
     query_name string,
     query_type string,
     query_class
       string,
     rcode string,
     answers array<
       struct<
         Rdata: string,
         Type: string,
         Class: string>
       >,
     srcaddr string,
     srcport int,
     transport string,
     srcids struct<
       instance: string,
       resolver_endpoint: string
       >,
     firewall_rule_action string,
     firewall_rule_group_id string,
     firewall_domain_list_id string
    )
        
   ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
   LOCATION 's3://amzn-s3-demo-bucket/AWSLogs/aws_account_id/vpcdnsquerylogs/{vpc-id}/'
   ```

   Resolver クエリログデータは JSON 形式であるため、CREATE TABLE ステートメントは [JSON SerDe ライブラリ](json-serde.md)を使用してデータを分析します。
**注記**  
SerDe では、各 JSON ドキュメントが、レコード内のフィールドを区切る行終端文字なしの、1 行のテキストに収まっていることを想定しています。JSON テキストがプリティプリント形式の場合、テーブルを作成した後にクエリを実行しようとすると、以下のようなエラーメッセージが表示される場合があります。「HIVE\$1CURSOR\$1ERROR: Row is not a valid JSON Object」、または「HIVE\$1CURSOR\$1ERROR: JsonParseException: Unexpected end-of-input: expected close marker for OBJECT」。詳細については、GitHub の OpenX SerDe のドキュメントで「[JSON Data Files](https://github.com/rcongiu/Hive-JSON-Serde#json-data-files)」(JSON データファイル) を参照してください。

1. **[Run query]** (クエリの実行) を選択します。ステートメントが `r53_rlogs` という名前の Athena テーブルを作成します。このテーブルの列は Resolver ログデータの各フィールドを表します。

1. Athena コンソールのクエリエディタで以下のクエリを実行して、テーブルが作成されたことを検証します。

   ```
   SELECT * FROM "r53_rlogs" LIMIT 10
   ```