

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 建立 CloudFront 即時日誌的資料表
<a name="create-cloudfront-table-real-time-logs"></a>

**建立 CloudFront 即時日誌檔案欄位的資料表**

1. 複製下列範例 DDL 陳述式，並將其貼到 Athena 主控台查詢編輯器。範例陳述式使用《Amazon CloudFront 開發人員指南**》中[即時日誌](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/real-time-logs.html)章節中所述的日誌檔案欄位。為存放日誌的 Amazon S3 儲存貯體修改 `LOCATION`。如需有關使用查詢編輯器的資訊，請參閱[開始使用](getting-started.md)。

   此查詢可指定 `ROW FORMAT DELIMITED` 和 `FIELDS TERMINATED BY '\t'`，表示欄位以定位字元分隔。對於 `ROW FORMAT DELIMITED`，Athena 預設使用 [LazySimpleSerDe](lazy-simple-serde.md)。因為在 Athena 中它是保留字，所以使用反引號 (') 逸出 `timestamp` 資料欄。如需相關資訊，請參閱[在查詢中逸出預留關鍵字](reserved-words.md)。

   下列範例包含所有可用的欄位。您可以註解排除或移除不需要的欄位。

   ```
   CREATE EXTERNAL TABLE IF NOT EXISTS cloudfront_real_time_logs ( 
   `timestamp` STRING,
   c_ip STRING,
   time_to_first_byte BIGINT,
   sc_status BIGINT,
   sc_bytes BIGINT,
   cs_method STRING,
   cs_protocol STRING,
   cs_host STRING,
   cs_uri_stem STRING,
   cs_bytes BIGINT,
   x_edge_location STRING,
   x_edge_request_id STRING,
   x_host_header STRING,
   time_taken BIGINT,
   cs_protocol_version STRING,
   c_ip_version STRING,
   cs_user_agent STRING,
   cs_referer STRING,
   cs_cookie STRING,
   cs_uri_query STRING,
   x_edge_response_result_type STRING,
   x_forwarded_for STRING,
   ssl_protocol STRING,
   ssl_cipher STRING,
   x_edge_result_type STRING,
   fle_encrypted_fields STRING,
   fle_status STRING,
   sc_content_type STRING,
   sc_content_len BIGINT,
   sc_range_start STRING,
   sc_range_end STRING,
   c_port BIGINT,
   x_edge_detailed_result_type STRING,
   c_country STRING,
   cs_accept_encoding STRING,
   cs_accept STRING,
   cache_behavior_path_pattern STRING,
   cs_headers STRING,
   cs_header_names STRING,
   cs_headers_count BIGINT,
   primary_distribution_id STRING,
   primary_distribution_dns_name STRING,
   origin_fbl STRING,
   origin_lbl STRING,
   asn STRING
   )
   ROW FORMAT DELIMITED 
   FIELDS TERMINATED BY '\t'
   LOCATION 's3://amzn-s3-demo-bucket/'
   TBLPROPERTIES ( 'skip.header.line.count'='2' )
   ```

1. 在 Athena 主控台中執行查詢。查詢完成之後，Athena 會註冊 `cloudfront_real_time_logs` 資料表，讓其中的資料可供您發出查詢。