

# IIS 로그 파일 형식 쿼리
<a name="querying-iis-logs-iis-log-file-format"></a>

W3C 확장 형식과 달리 [IIS 로그 파일 형식](https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2003/cc728311(v%3dws.10))에는 고정된 필드 집합이 있으며 구분 기호로 쉼표를 포함합니다. LazySimpleSerDe는 쉼표를 구분 기호로 처리하고 쉼표 뒤의 공백을 다음 필드의 시작으로 처리합니다.

다음 예제에서는 IIS 로그 파일 형식의 샘플 데이터를 보여 줍니다.

```
203.0.113.15, -, 2020-02-24, 22:48:38, W3SVC2, SERVER5, 198.51.100.4, 254, 501, 488, 200, 0, GET, /index.htm, -, 
203.0.113.4, -, 2020-02-24, 22:48:39, W3SVC2, SERVER6, 198.51.100.6, 147, 411, 388, 200, 0, GET, /about.html, -, 
203.0.113.11, -, 2020-02-24, 22:48:40, W3SVC2, SERVER7, 198.51.100.18, 170, 531, 468, 200, 0, GET, /image.png, -, 
203.0.113.8, -, 2020-02-24, 22:48:41, W3SVC2, SERVER8, 198.51.100.14, 125, 711, 868, 200, 0, GET, /intro.htm, -,
```

## Athena에서 IIS 로그 파일용 테이블 생성
<a name="querying-iis-logs-creating-a-table-in-athena-for-iis-log-files"></a>

Amazon S3의 IIS 로그를 쿼리하려면 먼저 테이블 스키마를 생성해야 Athena가 로그 데이터를 읽을 수 있습니다.

**Athena에서 IIS 로그 파일 형식 로그에 대한 테이블 생성**

1. [https://console.aws.amazon.com/athena/](https://console.aws.amazon.com/athena/home)에서 Athena 콘솔을 엽니다.

1. 다음의 DDL 문을 Athena 콘솔에 붙여 넣습니다. 다음 사항에 유의하세요.

   1. 쉼표 구분 기호를 지정하려면 `FIELDS TERMINATED BY ','`를 사용합니다.

   1. LOCATION 's3://amzn-s3-demo-bucket/*iis-log-file-folder*/'의 값을 Amazon S3의 IIS 로그 형식 로그 파일을 가리키도록 수정합니다.

   ```
   CREATE EXTERNAL TABLE `iis_format_logs`(
   client_ip_address string,
   user_name string,
   request_date string,
   request_time string,
   service_and_instance string,
   server_name string,
   server_ip_address string,
   time_taken_millisec string,
   client_bytes_sent string,
   server_bytes_sent string,
   service_status_code string,
   windows_status_code string,
   request_type string,
   target_of_operation string,
   script_parameters string
      )
   ROW FORMAT DELIMITED
     FIELDS TERMINATED BY ','
   STORED AS INPUTFORMAT
     'org.apache.hadoop.mapred.TextInputFormat'
   OUTPUTFORMAT
     'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
   LOCATION
     's3://amzn-s3-demo-bucket/iis-log-file-folder/'
   ```

1. Athena 콘솔에서 `iis_format_logs` 테이블을 등록하는 쿼리를 실행합니다. 이 쿼리가 완료되면 로그를 Athena에서 쿼리할 수 있습니다.

## IIS 로그 형식 셀렉트 쿼리 예제
<a name="querying-iis-logs-example-iis-log-format-select-query"></a>

다음 쿼리 예제는 `iis_format_logs` 테이블에서 요청 날짜, 요청 시간, 요청 대상, 걸린 시간(밀리초 단위)을 선택합니다. `WHERE` 절은 요청 유형이 `GET`이고 HTTP 상태 코드가 `200`(성공)인 경우를 필터링합니다. 쿼리가 성공하려면 쿼리에서 `' GET'` 및 `' 200'`에 선행하는 공백이 필요합니다.

```
SELECT request_date, request_time, target_of_operation, time_taken_millisec
FROM iis_format_logs
WHERE request_type = ' GET' AND service_status_code = ' 200'
```

다음 이미지는 샘플 데이터에 대한 쿼리 결과를 보여줍니다.

![\[Amazon S3에 저장된 IIS 로그 형식의 로그 파일에 대한 Athena의 쿼리 결과 예시.\]](http://docs.aws.amazon.com/ko_kr/athena/latest/ug/images/querying-iis-logs-2.png)
