選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

使用 JSON 的分割區投影在 Athena 中建立 CloudFront 日誌的資料表

焦點模式
使用 JSON 的分割區投影在 Athena 中建立 CloudFront 日誌的資料表 - Amazon Athena

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

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

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

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

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'='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 儲存貯體。

  • 分佈 IDs – 對於 projection.distributionid.values,如果您使用逗號分隔分佈 ID,則可以指定多個分佈 IDs。例如,<distributionID1><distributionID2>

  • 年範圍 – 在 中projection.year.range,您可以根據資料定義年範圍。例如,您可以將其調整為任何期間,例如 2025 年、2026 年。

    注意

    包含空分割區,例如未來日期的分割區 (例如:2025-2040),可能會影響查詢效能。不過,分割區投影旨在有效處理未來的日期。若要維持最佳效能,請確保仔細管理分割區,並盡可能避免過多的空白分割區。

  • 儲存位置範本 – 您必須確保根據下列 CloudFront 分割結構和 S3 路徑storage.location.template正確更新 。

    參數 模式
    CloudFront 分割結構 AWSLogs/{account_id}/CloudFront/{DistributionId}/folder2/{yyyy}/{MM}/{dd}/{HH}/folder3
    S3 路徑 s3://amzn-s3-demo-bucket/AWSLogs/account_id/CloudFront/E2Oxxxxxxxxxxx/folder2/2025/01/25/03/folder3/

    在您確認 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至關重要。

隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。