Crea una tabella per i log in tempo reale CloudFront - Amazon Athena

Crea una tabella per i log in tempo reale CloudFront

Per creare una tabella per i campi dei file log in tempo reale CloudFront
  1. 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 log documentati nella sezione Log in tempo reale della Guida per gli sviluppatori di Amazon CloudFront. Modifica il parametro LOCATION per il bucket Amazon S3 in cui sono archiviati i log. Per ulteriori informazioni sull'utilizzo dell'editor di query, consulta Inizia a usare.

    Questa query specifica ROW FORMAT DELIMITED e FIELDS TERMINATED BY '\t' per indicare che i campi sono delimitati da caratteri di tabulazione. Per ROW FORMAT DELIMITED, Athena usa LazySimpleSerDe di default. Nella colonna timestamp viene inserito il carattere escape con l'apice inverso (`) perché è una parola riservata in Athena. Per informazioni, consulta Impostare il carattere escape di parole chiave riservate nelle query.

    L'esempio seguente contiene tutti i campi disponibili. È possibile aggiungere commenti o rimuovere campi non servono.

    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' )
  2. Eseguire la query nella console Athena. Una volta completata la query, Athena registra la tabella cloudfront_real_time_logs, rendendo i dati in essa contenuti pronti per l'esecuzione di query.