本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
建立 ALB 存取日誌的資料表
-
將下列
CREATE TABLE陳述式複製並貼到 Athena 主控台的查詢編輯器中,然後視需要修改,以符合您自己的日誌項目需求。如需有關 Athena 主控台入門的資訊,請參閱開始使用。將LOCATION子句中的路徑取代為您的 Amazon S3 存取日誌資料夾位置。如需存取日誌檔案位置的詳細資訊,請參閱《Application Load Balancer 使用者指南》中的存取日誌檔案。如需每個日誌檔案欄位的資訊,請參閱《Application Load Balancer 使用者指南》中的存取日誌項目。
注意
下列範例
CREATE TABLE陳述式包含最近新增的classification、classification_reason和conn_trace_id(可追蹤性 ID 或 TID) 資料欄。若要為不包含這些項目的 Application Load Balancer 存取日誌建立資料表,請從CREATE TABLE陳述式中移除對應的欄,並相應地修改規則表達式。CREATE EXTERNAL TABLE IF NOT EXISTS alb_access_logs ( type string, time string, elb string, client_ip string, client_port int, target_ip string, target_port int, request_processing_time double, target_processing_time double, response_processing_time double, elb_status_code int, target_status_code string, received_bytes bigint, sent_bytes bigint, request_verb string, request_url string, request_proto string, user_agent string, ssl_cipher string, ssl_protocol string, target_group_arn string, trace_id string, domain_name string, chosen_cert_arn string, matched_rule_priority string, request_creation_time string, actions_executed string, redirect_url string, lambda_error_reason string, target_port_list string, target_status_code_list string, classification string, classification_reason string, conn_trace_id string ) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' WITH SERDEPROPERTIES ( 'serialization.format' = '1', 'input.regex' = '([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*)[:-]([0-9]*) ([-.0-9]*) ([-.0-9]*) ([-.0-9]*) (|[-0-9]*) (-|[-0-9]*) ([-0-9]*) ([-0-9]*) \"([^ ]*) (.*) (- |[^ ]*)\" \"([^\"]*)\" ([A-Z0-9-_]+) ([A-Za-z0-9.-]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" ([-.0-9]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \"([^ ]*)\" \"([^\\s]+?)\" \"([^\\s]+)\" \"([^ ]*)\" \"([^ ]*)\" ?([^ ]*)? ?( .*)?' ) LOCATION 's3://amzn-s3-demo-bucket/access-log-folder-path/'注意
我們建議在新增新的 ALB 日誌欄位時,
input.regex參數結尾的模式一律保持在適當位置,以處理未來的日誌項目。?( .*)? -
在 Athena 主控台中執行查詢。查詢完成之後,Athena 會註冊
alb_access_logs資料表,讓其中的資料可供您發出查詢。