

# ALB 액세스 로그용 테이블 생성
<a name="create-alb-access-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-access-logs.html#access-log-file-format)을 참조하세요.

   각 로그 파일 필드에 대한 자세한 내용은 *Application Load Balancer 사용 설명서*의 [액세스 로그 항목](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-log-entry-format)을 참조하세요.
**참고**  
다음 예제 `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` 파라미터 끝에 있는 {{`?( .*)?`}} 패턴을 항상 유지하는 것이 좋습니다.

1. Athena 콘솔에서 쿼리를 실행합니다. 쿼리가 완료된 후 Athena는 `alb_access_logs` 테이블을 등록하여 쿼리를 실행할 수 있도록 데이터를 준비합니다.