Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Per creare una tabella per i campi CloudFront standard dei file di registro utilizzando un formato JSON
-
Copia e incolla la seguente istruzione DDL di esempio nell'Editor di query della console Athena. L'istruzione di esempio utilizza i campi del file di registro documentati nella sezione Campi dei file di log standard della Amazon CloudFront Developer Guide. Modifica il parametro
LOCATION
per il bucket Amazon S3 in cui sono archiviati i log.Questa query utilizza OpenX JSON SerDe con le seguenti SerDe proprietà per leggere correttamente i campi JSON in Athena.
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/'
-
Eseguire la query nella console Athena. Una volta completata la query, Athena registra la tabella
cf_logs_manual_partition_json
, rendendo i dati in essa contenuti pronti per l'esecuzione di query.
Query di esempio
La seguente query somma il numero di byte serviti CloudFront per il 15 gennaio 2025.
SELECT sum(cast("sc-bytes" as BIGINT)) as sc
FROM cf_logs_manual_partition_json
WHERE "date"='2025-01-15'
Per eliminare righe duplicate (ad esempio, righe vuote duplicate) dai risultati della query, è possibile utilizzare l'istruzione SELECT DISTINCT
, come nell'esempio seguente.
SELECT DISTINCT * FROM cf_logs_manual_partition_json