

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

# 建立 ALB 連線日誌的資料表
<a name="create-alb-connection-logs-table"></a>

1. 複製下列範例 `CREATE TABLE` 陳述式，並將其貼到 Athena 主控台查詢編輯器，然後針對自己的日誌項目要求視需要進行修改。如需有關 Athena 主控台入門的資訊，請參閱[開始使用](getting-started.md)。將 `LOCATION` 子句中的路徑取代為您的 Amazon S3 連線日誌資料夾位置。如需有關連線日誌檔案位置的詳細資訊，請參閱《Application Load Balancer 使用者指南**》中的[連線日誌檔案](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-connection-logs.html#connection-log-file-format)。如需有關每個日誌檔案欄位的資訊，請參閱[連線日誌項目](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-connection-logs.html#connection-log-entry-format)。

   ```
   CREATE EXTERNAL TABLE IF NOT EXISTS alb_connection_logs (
            time string,
            client_ip string,
            client_port int,
            listener_port int,
            tls_protocol string,
            tls_cipher string,
            tls_handshake_latency double,
            leaf_client_cert_subject string,
            leaf_client_cert_validity string,
            leaf_client_cert_serial_number string,
            tls_verify_status 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]*) ([A-Za-z0-9.-]*) ([^ ]*) ([-.0-9]*) \"([^\"]*)\" ([^ ]*) ([^ ]*) ([^ ]*) ?([^ ]*)?( .*)?'
            )
            LOCATION 's3://amzn-s3-demo-bucket/{{connection-log-folder-path}}/'
   ```

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