

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

# 查詢 Amazon CloudFront 日誌
<a name="cloudfront-logs"></a>

您可以設定 Amazon CloudFront CDN 來將 Web 分佈存取日誌匯出至 Amazon Simple Storage Service。使用這些日誌來探索使用者的瀏覽模式，其涵蓋 CloudFront 提供的所有 Web 屬性。

開始查詢日誌之前，請在您偏好的 CloudFront 分佈中啟用 Web 分佈存取日誌。如需相關資訊，請參閱《Amazon CloudFront 開發人員指南》**中的[存取日誌](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html)。記下儲存這些日誌的 Amazon S3 儲存貯體。

**Topics**
+ [建立 CloudFront 標準日誌的資料表 (舊版)](create-cloudfront-table-standard-logs.md)
+ [使用手動分割 (JSON) 在 Athena 中建立 CloudFront 日誌的資料表](create-cloudfront-table-manual-json.md)
+ [使用手動分割 (Parquet) 在 Athena 中建立 CloudFront 日誌的資料表](create-cloudfront-table-manual-parquet.md)
+ [使用分割區投影 (JSON) 在 Athena 中建立 CloudFront 日誌的資料表](create-cloudfront-table-partition-json.md)
+ [使用分割區投影 (Parquet) 在 Athena 中建立 CloudFront 日誌的資料表](create-cloudfront-table-partition-parquet.md)
+ [建立 CloudFront 即時日誌的資料表](create-cloudfront-table-real-time-logs.md)
+ [其他資源](cloudfront-logs-additional-resources.md)

# 建立 CloudFront 標準日誌的資料表 (舊版)
<a name="create-cloudfront-table-standard-logs"></a>

**注意**  
下列程序適用於 CloudFront 中的 Web 分佈存取日誌。不適用於來自 RTMP 分佈的串流日誌。

**建立 CloudFront 標準日誌檔案欄位的資料表**

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

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

   ```
   CREATE EXTERNAL TABLE IF NOT EXISTS cloudfront_standard_logs (
     `date` DATE,
     time STRING,
     x_edge_location STRING,
     sc_bytes BIGINT,
     c_ip STRING,
     cs_method STRING,
     cs_host STRING,
     cs_uri_stem STRING,
     sc_status INT,
     cs_referrer STRING,
     cs_user_agent STRING,
     cs_uri_query STRING,
     cs_cookie STRING,
     x_edge_result_type STRING,
     x_edge_request_id STRING,
     x_host_header STRING,
     cs_protocol STRING,
     cs_bytes BIGINT,
     time_taken FLOAT,
     x_forwarded_for STRING,
     ssl_protocol STRING,
     ssl_cipher STRING,
     x_edge_response_result_type STRING,
     cs_protocol_version STRING,
     fle_status STRING,
     fle_encrypted_fields INT,
     c_port INT,
     time_to_first_byte FLOAT,
     x_edge_detailed_result_type STRING,
     sc_content_type STRING,
     sc_content_len BIGINT,
     sc_range_start BIGINT,
     sc_range_end BIGINT
   )
   ROW FORMAT DELIMITED 
   FIELDS TERMINATED BY '\t'
   LOCATION 's3://amzn-s3-demo-bucket/'
   TBLPROPERTIES ( 'skip.header.line.count'='2' )
   ```

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

## 查詢範例
<a name="query-examples-cloudfront-logs"></a>

以下查詢加總 CloudFront 在 2018 年 6 月 9 日到 6 月 11 日之間提供的位元組數。以雙引號圍住日期欄名稱，因為它是保留字。

```
SELECT SUM(bytes) AS total_bytes
FROM cloudfront_standard_logs
WHERE "date" BETWEEN DATE '2018-06-09' AND DATE '2018-06-11'
LIMIT 100;
```

若要從查詢結果中除去重複的資料列 (例如，重複的空白資料列)，您可以使用 `SELECT DISTINCT` 陳述式，如下列範例所示。

```
SELECT DISTINCT * 
FROM cloudfront_standard_logs 
LIMIT 10;
```

# 使用手動分割 (JSON) 在 Athena 中建立 CloudFront 日誌的資料表
<a name="create-cloudfront-table-manual-json"></a>

**使用 JSON 格式建立 CloudFront 標準日誌檔案欄位的資料表**

1. 複製下列範例 DDL 陳述式，並將其貼到 Athena 主控台查詢編輯器。範例陳述式使用《**Amazon CloudFront 開發人員指南》中[標準日誌檔欄位](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html#BasicDistributionFileFormat)章節中所述的日誌檔欄位。為存放日誌的 Amazon S3 儲存貯體修改 `LOCATION`。

   此查詢會搭配下列 SerDe 屬性使用 OpenX JSON SerDe，以在 Athena 中正確讀取 JSON 欄位。

   ```
   CREATE EXTERNAL TABLE `cf_logs_manual_partition_json`(
     `date` string , 
     `time` string , 
     `x-edge-location` string , 
     `sc-bytes` string , 
     `c-ip` string , 
     `cs-method` string , 
     `cs(host)` string , 
     `cs-uri-stem` string , 
     `sc-status` string , 
     `cs(referer)` string , 
     `cs(user-agent)` string , 
     `cs-uri-query` string , 
     `cs(cookie)` string , 
     `x-edge-result-type` string , 
     `x-edge-request-id` string , 
     `x-host-header` string , 
     `cs-protocol` string , 
     `cs-bytes` string , 
     `time-taken` string , 
     `x-forwarded-for` string , 
     `ssl-protocol` string , 
     `ssl-cipher` string , 
     `x-edge-response-result-type` string , 
     `cs-protocol-version` string , 
     `fle-status` string , 
     `fle-encrypted-fields` string , 
     `c-port` string , 
     `time-to-first-byte` string , 
     `x-edge-detailed-result-type` string , 
     `sc-content-type` string , 
     `sc-content-len` string , 
     `sc-range-start` string , 
     `sc-range-end` string )
   ROW FORMAT SERDE 
     'org.openx.data.jsonserde.JsonSerDe' 
   WITH SERDEPROPERTIES ( 
     'paths'='c-ip,c-port,cs(Cookie),cs(Host),cs(Referer),cs(User-Agent),cs-bytes,cs-method,cs-protocol,cs-protocol-version,cs-uri-query,cs-uri-stem,date,fle-encrypted-fields,fle-status,sc-bytes,sc-content-len,sc-content-type,sc-range-end,sc-range-start,sc-status,ssl-cipher,ssl-protocol,time,time-taken,time-to-first-byte,x-edge-detailed-result-type,x-edge-location,x-edge-request-id,x-edge-response-result-type,x-edge-result-type,x-forwarded-for,x-host-header') 
   STORED AS INPUTFORMAT 
     'org.apache.hadoop.mapred.TextInputFormat' 
   OUTPUTFORMAT 
     'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
   LOCATION
     's3://amzn-s3-demo-bucket/'
   ```

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

## 查詢範例
<a name="query-examples-cloudfront-logs-manual-json"></a>

下列查詢加總 CloudFront 在 2025 年 1 月 15 日提供的位元組數。

```
SELECT sum(cast("sc-bytes" as BIGINT)) as sc
FROM cf_logs_manual_partition_json
WHERE "date"='2025-01-15'
```

若要從查詢結果中除去重複的資料列 (例如，重複的空白資料列)，您可以使用 `SELECT DISTINCT` 陳述式，如下列範例所示。

```
SELECT DISTINCT * FROM cf_logs_manual_partition_json
```

# 使用手動分割 (Parquet) 在 Athena 中建立 CloudFront 日誌的資料表
<a name="create-cloudfront-table-manual-parquet"></a>

**使用 Parquet 格式建立 CloudFront 標準日誌檔案欄位的資料表**

1. 複製下列範例 DDL 陳述式，並將其貼到 Athena 主控台查詢編輯器。範例陳述式使用《**Amazon CloudFront 開發人員指南》中[標準日誌檔欄位](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html#BasicDistributionFileFormat)章節中所述的日誌檔欄位。

   此查詢會搭配下列 SerDe 屬性使用 ParquetHiveSerDe，以在 Athena 中正確讀取 Parquet 欄位。

   ```
   CREATE EXTERNAL TABLE `cf_logs_manual_partition_parquet`(
     `date` string, 
     `time` string, 
     `x_edge_location` string, 
     `sc_bytes` string, 
     `c_ip` string, 
     `cs_method` string, 
     `cs_host` string, 
     `cs_uri_stem` string, 
     `sc_status` string, 
     `cs_referer` string, 
     `cs_user_agent` string, 
     `cs_uri_query` string, 
     `cs_cookie` string, 
     `x_edge_result_type` string, 
     `x_edge_request_id` string, 
     `x_host_header` string, 
     `cs_protocol` string, 
     `cs_bytes` string, 
     `time_taken` string, 
     `x_forwarded_for` string, 
     `ssl_protocol` string, 
     `ssl_cipher` string, 
     `x_edge_response_result_type` string, 
     `cs_protocol_version` string, 
     `fle_status` string, 
     `fle_encrypted_fields` string, 
     `c_port` string, 
     `time_to_first_byte` string, 
     `x_edge_detailed_result_type` string, 
     `sc_content_type` string, 
     `sc_content_len` string, 
     `sc_range_start` string, 
     `sc_range_end` string)
   ROW FORMAT SERDE 
     'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
   STORED AS INPUTFORMAT 
     'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
   OUTPUTFORMAT 
     'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
   LOCATION
     's3://amzn-s3-demo-bucket/'
   ```

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

## 查詢範例
<a name="query-examples-cloudfront-logs-manual-parquet"></a>

下列查詢加總 CloudFront 在 2025 年 1 月 19 日提供的位元組數。

```
SELECT sum(cast("sc_bytes" as BIGINT)) as sc
FROM cf_logs_manual_partition_parquet
WHERE "date"='2025-01-19'
```

若要從查詢結果中除去重複的資料列 (例如，重複的空白資料列)，您可以使用 `SELECT DISTINCT` 陳述式，如下列範例所示。

```
SELECT DISTINCT * FROM cf_logs_manual_partition_parquet
```

# 使用分割區投影 (JSON) 在 Athena 中建立 CloudFront 日誌的資料表
<a name="create-cloudfront-table-partition-json"></a>

您可以使用 Athena 分割區投影功能減少查詢執行時期並自動化分割區管理。分割區投影會在新增資料時自動新增分割區。因此您無需使用 `ALTER TABLE ADD PARTITION` 手動新增分割區。

下列 CREATE TABLE 陳述式範例會從指定 CloudFront 分佈到現在，對單一 AWS 區域的 CloudFront 日誌自動使用分割區投影。成功執行查詢之後，您可以查詢資料表。

```
CREATE EXTERNAL TABLE `cloudfront_logs_pp`(
  `date` string, 
  `time` string, 
  `x-edge-location` string, 
  `sc-bytes` string, 
  `c-ip` string, 
  `cs-method` string, 
  `cs(host)` string, 
  `cs-uri-stem` string, 
  `sc-status` string, 
  `cs(referer)` string, 
  `cs(user-agent)` string, 
  `cs-uri-query` string, 
  `cs(cookie)` string, 
  `x-edge-result-type` string, 
  `x-edge-request-id` string, 
  `x-host-header` string, 
  `cs-protocol` string, 
  `cs-bytes` string, 
  `time-taken` string, 
  `x-forwarded-for` string, 
  `ssl-protocol` string, 
  `ssl-cipher` string, 
  `x-edge-response-result-type` string, 
  `cs-protocol-version` string, 
  `fle-status` string, 
  `fle-encrypted-fields` string, 
  `c-port` string, 
  `time-to-first-byte` string, 
  `x-edge-detailed-result-type` string, 
  `sc-content-type` string, 
  `sc-content-len` string, 
  `sc-range-start` string, 
  `sc-range-end` string)
  PARTITIONED BY(
         distributionid string,
         year int,
         month int,
         day int,
         hour int )
ROW FORMAT SERDE 
  'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES ( 
  'paths'='c-ip,c-port,cs(Cookie),cs(Host),cs(Referer),cs(User-Agent),cs-bytes,cs-method,cs-protocol,cs-protocol-version,cs-uri-query,cs-uri-stem,date,fle-encrypted-fields,fle-status,sc-bytes,sc-content-len,sc-content-type,sc-range-end,sc-range-start,sc-status,ssl-cipher,ssl-protocol,time,time-taken,time-to-first-byte,x-edge-detailed-result-type,x-edge-location,x-edge-request-id,x-edge-response-result-type,x-edge-result-type,x-forwarded-for,x-host-header') 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  's3://amzn-s3-demo-bucket/AWSLogs/AWS_ACCOUNT_ID/CloudFront/'
TBLPROPERTIES (
  'projection.distributionid.type'='enum',
  'projection.distributionid.values'='E2Oxxxxxxxxxxx',
  'projection.day.range'='01,31', 
  'projection.day.type'='integer', 
  'projection.day.digits'='2', 
  'projection.enabled'='true', 
  'projection.month.range'='01,12', 
  'projection.month.type'='integer', 
  'projection.month.digits'='2', 
  'projection.year.range'='2025,2026', 
  'projection.year.type'='integer', 
  'projection.hour.range'='00,23',
  'projection.hour.type'='integer',
  'projection.hour.digits'='2',
  'storage.location.template'='s3://amzn-s3-demo-bucket/AWSLogs/AWS_ACCOUNT_ID/CloudFront/${distributionid}/${year}/${month}/${day}/${hour}/')
```

以下是先前範例中所用屬性的一些考量事項。
+ **資料表名稱** – 資料表名稱 *`cloudfront_logs_pp`* 為可取代。您可以將其變更為您偏好的任何名稱。
+ **位置** – 修改 `s3://amzn-s3-demo-bucket/AWSLogs/AWS_ACCOUNT_ID/` 來指向您的 Amazon S3 儲存貯體。
+ **分佈 ID** – 對於 `projection.distributionid.values`，如果您使用逗號分隔分佈 ID，則可以指定多個分佈 ID。例如，*<distributionID1>*、*<distributionID2>*。
+ **年份範圍** – 在 `projection.year.range` 中，您可以根據資料定義年份範圍。例如，您可以將其調整為任何期間，例如 *2025 年*、*2026 年*。
**注意**  
包含空的分割區 (例如未來日期的分割區，例如：2025-2040 年) 可能會影響查詢效能。不過，分割區投影旨在有效地處理未來日期。為了維持最佳效能，請確保仔細管理分割區，並盡可能避免過多的空的分割區。
+ **儲存位置範本** – 您必須確保根據下列 CloudFront 分割結構和 S3 路徑正確更新 `storage.location.template`。  
****    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/athena/latest/ug/create-cloudfront-table-partition-json.html)

  在確認 CloudFront 分割結構和 S3 結構符合所需的模式後，請更新 `storage.location.template`，如下所示：

  ```
  'storage.location.template'='s3://amzn-s3-demo-bucket/AWSLogs/account_id/CloudFront/${distributionid}/folder2/${year}/${month}/${day}/${hour}/folder3/'
  ```
**注意**  
`storage.location.template` 的適當組態對於確保正確的資料儲存和擷取至關重要。

# 使用分割區投影 (Parquet) 在 Athena 中建立 CloudFront 日誌的資料表
<a name="create-cloudfront-table-partition-parquet"></a>

下列 CREATE TABLE 陳述式範例會從指定 CloudFront 分佈到現在，對單一 AWS 區域的 Parquet 格式 CloudFront 日誌自動使用分割區投影。成功執行查詢之後，您可以查詢資料表。

```
CREATE EXTERNAL TABLE `cloudfront_logs_parquet_pp`(
`date` string, 
`time` string, 
`x_edge_location` string, 
`sc_bytes` string, 
`c_ip` string, 
`cs_method` string, 
`cs_host` string, 
`cs_uri_stem` string, 
`sc_status` string, 
`cs_referer` string, 
`cs_user_agent` string, 
`cs_uri_query` string, 
`cs_cookie` string, 
`x_edge_result_type` string, 
`x_edge_request_id` string, 
`x_host_header` string, 
`cs_protocol` string, 
`cs_bytes` string, 
`time_taken` string, 
`x_forwarded_for` string, 
`ssl_protocol` string, 
`ssl_cipher` string, 
`x_edge_response_result_type` string, 
`cs_protocol_version` string, 
`fle_status` string, 
`fle_encrypted_fields` string, 
`c_port` string, 
`time_to_first_byte` string, 
`x_edge_detailed_result_type` string, 
`sc_content_type` string, 
`sc_content_len` string, 
`sc_range_start` string, 
`sc_range_end` string)
PARTITIONED BY(
 distributionid string,
 year int,
 month int,
 day int,
 hour int )
ROW FORMAT SERDE 
'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
STORED AS INPUTFORMAT 
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
OUTPUTFORMAT 
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
's3://amzn-s3-demo-bucket/AWSLogs/AWS_ACCOUNT_ID/CloudFront/'
TBLPROPERTIES (
'projection.distributionid.type'='enum',
'projection.distributionid.values'='E3OK0LPUNWWO3',
'projection.day.range'='01,31',
'projection.day.type'='integer',
'projection.day.digits'='2',
'projection.enabled'='true',
'projection.month.range'='01,12',
'projection.month.type'='integer',
'projection.month.digits'='2',
'projection.year.range'='2019,2025',
'projection.year.type'='integer',
'projection.hour.range'='01,12',
'projection.hour.type'='integer',
'projection.hour.digits'='2',
'storage.location.template'='s3://amzn-s3-demo-bucket/AWSLogs/AWS_ACCOUNT_ID/CloudFront/${distributionid}/${year}/${month}/${day}/${hour}/')
```

以下是先前範例中所用屬性的一些考量事項。
+ **資料表名稱** – 資料表名稱 *`cloudfront_logs_pp`* 為可取代。您可以將其變更為您偏好的任何名稱。
+ **位置** – 修改 `s3://amzn-s3-demo-bucket/AWSLogs/AWS_ACCOUNT_ID/` 來指向您的 Amazon S3 儲存貯體。
+ **分佈 ID** – 對於 `projection.distributionid.values`，如果您使用逗號分隔分佈 ID，則可以指定多個分佈 ID。例如，*<distributionID1>*、*<distributionID2>*。
+ **年份範圍** – 在 `projection.year.range` 中，您可以根據資料定義年份範圍。例如，您可以將其調整為任何期間，例如 *2025 年*、*2026 年*。
**注意**  
包含空的分割區 (例如未來日期的分割區，例如：2025-2040 年) 可能會影響查詢效能。不過，分割區投影旨在有效地處理未來日期。為了維持最佳效能，請確保仔細管理分割區，並盡可能避免過多的空的分割區。
+ **儲存位置範本** – 您必須確保根據下列 CloudFront 分割結構和 S3 路徑正確更新 `storage.location.template`。  
****    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/athena/latest/ug/create-cloudfront-table-partition-parquet.html)

  在確認 CloudFront 分割結構和 S3 結構符合所需的模式後，請更新 `storage.location.template`，如下所示：

  ```
  'storage.location.template'='s3://amzn-s3-demo-bucket/AWSLogs/account_id/CloudFront/${distributionid}/folder2/${year}/${month}/${day}/${hour}/folder3/'
  ```
**注意**  
`storage.location.template` 的適當組態對於確保正確的資料儲存和擷取至關重要。

# 建立 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` 資料表，讓其中的資料可供您發出查詢。

# 其他資源
<a name="cloudfront-logs-additional-resources"></a>

如需有關使用 Athena 查詢 CloudFront 日誌的詳細資訊，請參閱 [AWS 大數據部落格](https://aws.amazon.com/blogs/big-data/)中的下列貼文。

[使用 Amazon Athena 輕鬆查詢 AWS 服務 日誌](https://aws.amazon.com/blogs/big-data/easily-query-aws-service-logs-using-amazon-athena/) (2019 年 5 月 29 日）。

[大規模分析 Amazon CloudFront 存取日誌](https://aws.amazon.com/blogs/big-data/analyze-your-amazon-cloudfront-access-logs-at-scale/) (2018 年 12 月 21 日)。

[建置無伺服器架構，使用 AWS Lambda、Amazon Athena 和 Amazon Managed Service for Apache Flink (2017 年 5 月 26 日） 來分析 Amazon CloudFront 存取日誌 Amazon Athena](https://aws.amazon.com/blogs/big-data/build-a-serverless-architecture-to-analyze-amazon-cloudfront-access-logs-using-aws-lambda-amazon-athena-and-amazon-kinesis-analytics/)。