# 데이터 연동 - 데이터 추출하기 (Data Export)

{% hint style="info" %}
엔터프라이즈 플랜에서만 지원하는 기능입니다.
{% endhint %}

### 데이터 추출하기 (Data Export)

데이터 추출 (Data Export) 기능을 통해서핵클에 저장되어 있는 Raw 데이터를 고객사의 AWS S3, GCP GCS 와 같은 저장소로 내보낼 수 있습니다. 데이터 추출 기능은 일별 (Daily) 로 데이터를 전송합니다.

#### 지원 가능 저장소 (Supported Cloud Storage)

| 클라우드 | 저장소      | 지원 여부 |
| ---- | -------- | ----- |
| AWS  | S3       | Y     |
| AWS  | Redshift | 지원 예정 |
| GCP  | GCS      | Y     |
| GCP  | BigQuery | 지원 예정 |

#### 사전 준비 (Requirements)

데이터 추출 전 다음 작업이 필요합니다.

* [x] Raw 데이터를 전송 받을 저장소를 생성합니다. (AWS S3, GCP GCS 등)
* [x] Raw 데이터를 전송 받을 저장소를 위한 Key 를 생성하고 필요한 권한을 부여합니다.

**Key 생성 및 권한 부여: GCP GCS**

GCP GCS 의 경우 [GCP IAM > 서비스 계정 키 생성 및 관리](https://cloud.google.com/iam/docs/creating-managing-service-account-keys?hl=ko) 문서를 참고해 Key 를 생성할 수 있습니다.

GCS 접근을 위한 Key 생성시 아래의 권한이 필요합니다.

```
storage.buckets.get
storage.objects.get
storage.objects.create
storage.objects.delete
storage.objects.list
```

**Key 생성 및 권한 부여: AWS S3**

AWS S3의 경우 다음 문서들을 참고해 Key를 생성하고 필요한 권한을 부여할 수 있습니다.

1. [AWS Docs: IAM Role 생성하기](https://docs.aws.amazon.com/ko_kr/IAM/latest/UserGuide/id_roles_create_for-user.html) 문서를 따라 AWS IAM User 를 생성합니다.
2. [AWS Docs: IAM Policy 생성하기](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create-console.html#access_policies_create-start) 를 따라 Policy 를 생성하고 아래 코드로 `iam_policy.json` 라는 이름으로 첨부된 IAM Policy 정책을 포함해 생성합니다. 이후 이전 단계에서 생성한 IAM Role 에 IAM Policy 정책을 추가합니다.
3. [AWS Docs: IAM STS 설정하기](https://docs.aws.amazon.com/ko_kr/IAM/latest/UserGuide/id_roles_create_policy-examples.html#id_roles_create_policy-examples-access-to-services) 문서를 따라 아래 `iam_sts.json` 라는 이름으로 첨부된 IAM STS 정책을 생성했던 IAM Role 에 추가합니다. 이때, 핵클로 부터 제공받은 ARN 값을 입력합니다. 또한 직접 지정한 `sts:ExternalId` 값을 핵클에게 전달합니다.

```json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
              "s3:GetObject",
              "s3:GetObjectVersion",
              "s3:DeleteObject",
              "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::<bucket>/<prefix>/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetBucketLocation"
            ],
            "Resource": "arn:aws:s3:::<bucket>"
        }
    ]
}
```

```json
{
 "Version": "2012-10-17",
 "Statement": [
   {
     "Effect": "Allow",
     "Principal": {
       "AWS": "[핵클제공_ARN]"
     },
     "Action": "sts:AssumeRole",
     "Condition": {
       "StringEquals": {
         "sts:ExternalId": "[고객사지정_랜덤문자]"
       }
     }
   }
 ]
}
```

#### 데이터 추출 결과 예시 (Data Export Sample)

핵클로 전송된 Raw 데이터가 추출될 때는 [Apache Parquet](https://parquet.apache.org/) 형식으로 전달됩니다. 아래는 전달되는 Parquet 형식 데이터의 스키마입니다.

```json
root
 |-- server_dt: date (nullable = false)
 |-- ts: timestamp (nullable = false)
 |-- environment: string (nullable = false)
 |-- event_key: string (nullable = false)
 |-- identifiers: string (nullable = false)
 |-- insert_id: string (nullable = false)
 |-- metric_value: decimal(24,6) (nullable = false)
 |-- hackle_properties: string (nullable = false)
 |-- user_properties: string (nullable = false)
 |-- event_properties: string (nullable = false)
```

#### 데이터 추출 요청

데이터 추출 요청은 핵클로 문의 부탁드립니다. 데이터 추출하기를 위해 다음 정보가 필요합니다.

* [x] 접근을 위해 권한이 부여된 Key
* [x] AWS S3, GCS Bucket 이름 및 Bucket 내 데이터가 적재될 파티션 경로 (예시: `gcs://customer-data-hackle/prefix-custom/` 이하는 핵클이 정의한 값)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/data-link/data-integration-data-export.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
