

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# EMR Serverless에 대한 메타스토어 구성
<a name="metastore-config"></a>

*Hive 메타스토어*는 스키마, 파티션 이름 및 데이터 유형을 포함하여 테이블에 대한 구조 정보를 저장하는 중앙 집중식 위치입니다. EMR Serverless를 사용하면 작업에 액세스할 수 있는 메타스토어에서 이 테이블 메타데이터를 유지할 수 있습니다.

Hive 메타스토어에 대한 두 가지 옵션이 있습니다.
+  AWS Glue 데이터 카탈로그
+ 외부 Apache Hive 메타스토어

## Glue 데이터 카탈로그를 AWS 메타스토어로 사용
<a name="glue-metastore"></a>

Glue 데이터 카탈로그를 AWS 메타스토어로 사용하도록 Spark 및 Hive 작업을 구성할 수 있습니다. 영구 메타스토어가 필요하거나 여러 애플리케이션, 서비스 또는 AWS 계정에서 메타스토어를 공유해야 하는 경우에 이 구성을 사용하는 것이 좋습니다. 데이터 카탈로그에 대한 자세한 내용은 [AWS Glue 데이터 카탈로그 채우기를 참조하세요](https://docs.aws.amazon.com/glue/latest/dg/populate-data-catalog.html). AWS Glue 요금에 대한 자세한 내용은 [AWS Glue 요금을](https://aws.amazon.com/glue/pricing) 참조하세요.

애플리케이션 AWS 계정 과 동일한 또는 다른에서 AWS Glue 데이터 카탈로그를 사용하도록 EMR Serverless 작업을 구성할 수 있습니다 AWS 계정.

### AWS Glue 데이터 카탈로그 구성
<a name="glue-metastore-configure"></a>

Data Catalog를 구성하려면 사용할 EMR Serverless 애플리케이션 유형을 선택합니다.

------
#### [ Spark ]

EMR Studio를 사용하여 EMR Serverless Spark 애플리케이션에서 작업을 실행하는 경우 Glue 데이터 카탈로그가 기본 AWS 메타스토어입니다.

SDKs 사용하는 경우 작업 실행의 `sparkSubmit` 파라미터`com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory`에서 `spark.hadoop.hive.metastore.client.factory.class` 구성을 로 AWS CLI설정합니다. 다음 예제에서는 AWS CLI를 사용하여 Data Catalog를 구성하는 방법을 보여줍니다.

```
aws emr-serverless start-job-run \
    --application-id {{application-id}} \
    --execution-role-arn {{job-role-arn}} \
    --job-driver '{
        "sparkSubmit": {
            "entryPoint": "s3://{{amzn-s3-demo-bucket}}/code/pyspark/extreme_weather.py",
            "sparkSubmitParameters": "--conf spark.hadoop.hive.metastore.client.factory.class=com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory --conf spark.driver.cores=1 --conf spark.driver.memory=3g --conf spark.executor.cores=4 --conf spark.executor.memory=3g"
        }
    }'
```

또는 Spark 코드에서 새 `SparkSession`을 생성할 때 이 구성을 설정할 수 있습니다.

```
from pyspark.sql import SparkSession

spark = (
    SparkSession.builder.appName("SparkSQL")
    .config(
        "spark.hadoop.hive.metastore.client.factory.class",
        "com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory",
    )
    .enableHiveSupport()
    .getOrCreate()
)

# we can query tables with SparkSQL
spark.sql("SHOW TABLES").show()

# we can also them with native Spark
print(spark.catalog.listTables())
```

------
#### [ Hive ]

EMR Serverless Hive 애플리케이션의 경우 Data Catalog가 기본 메타스토어입니다. 즉, EMR Serverless Hive 애플리케이션에서 작업을 실행하면 Hive는 애플리케이션 AWS 계정 과 동일한의 데이터 카탈로그에 메타스토어 정보를 기록합니다. Data Catalog를 메타스토어로 사용하기 위해 가상 프라이빗 클라우드(VPC)가 필요하지 않습니다.

Hive 메타스토어 테이블에 액세스하려면 AWS Glue에 [대한 IAM 권한 설정에 설명된 필수 AWS Glue](https://docs.aws.amazon.com/glue/latest/dg/getting-started-access.html) 정책을 추가합니다.

------

### EMR Serverless 및 AWS Glue 데이터 카탈로그에 대한 교차 계정 액세스 구성
<a name="glue-metastore-cross-account"></a>

EMR Serverless에 대한 교차 계정 액세스를 설정하려면 먼저 AWS 계정다음에 로그인합니다.
+ `AccountA` - EMR Serverless 애플리케이션을 생성한 AWS 계정 입니다.
+ `AccountB` - EMR Serverless 작업이 액세스하도록 실행하려는 AWS Glue 데이터 카탈로그가 AWS 계정 포함된 입니다.

1. `AccountB`의 관리자 또는 기타 승인된 자격 증명이 `AccountB`의 Data Catalog에 리소스 정책을 연결해야 합니다. 이 정책은 `AccountB` 카탈로그의 리소스에서 작업을 수행할 수 있는 `AccountA`별 교차 계정 권한을 부여합니다.

------
#### [ JSON ]

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Action": [
           "glue:GetDatabase",
           "glue:CreateDatabase",
           "glue:GetDataBases",
           "glue:CreateTable",
           "glue:GetTable",
           "glue:UpdateTable",
           "glue:DeleteTable",
           "glue:GetTables",
           "glue:GetPartition",
           "glue:GetPartitions",
           "glue:CreatePartition",
           "glue:BatchCreatePartition",
           "glue:GetUserDefinedFunctions"
         ],
         "Resource": [
           "arn:aws:glue:*:123456789012:catalog"
         ],
         "Sid": "AllowGLUEGetdatabase"
       }
     ]
   }
   ```

------

1. 역할이 `AccountB`의 Data Catalog 리소스에 액세스할 수 있도록 `AccountA`에서 EMR Serverless 작업 런타임 역할에 IAM 정책을 추가합니다.

------
#### [ JSON ]

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Action": [
           "glue:GetDatabase",
           "glue:CreateDatabase",
           "glue:GetDataBases",
           "glue:CreateTable",
           "glue:GetTable",
           "glue:UpdateTable",
           "glue:DeleteTable",
           "glue:GetTables",
           "glue:GetPartition",
           "glue:GetPartitions",
           "glue:CreatePartition",
           "glue:BatchCreatePartition",
           "glue:GetUserDefinedFunctions"
         ],
         "Resource": [
           "arn:aws:glue:*:123456789012:catalog"
         ],
         "Sid": "AllowGLUEGetdatabase"
       }
     ]
   }
   ```

------

1.  작업 실행을 시작합니다. 이 단계는 `AccountA`의 EMR Serverless 애플리케이션 유형에 따라 약간 다릅니다.

------
#### [ Spark ]

   다음 예제와 같이 `spark.hadoop.hive.metastore.glue.catalogid`에서 `sparkSubmitParameters` 속성을 설정합니다. {{`AccountB-catalog-id`}}를 `AccountB`의 Data Catalog ID로 바꿉니다.

   ```
   aws emr-serverless start-job-run \
   --application-id "{{application-id}}" \
   --execution-role-arn "{{job-role-arn}}" \
   --job-driver '{
       "sparkSubmit": {
           "entryPoint": "s3://{{amzn-s3-demo-bucket}}/scripts/test.py",
            "sparkSubmitParameters": "--conf spark.hadoop.hive.metastore.client.factory.class=com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory --conf spark.hadoop.hive.metastore.glue.catalogid={{AccountB-catalog-id}} --conf spark.executor.cores=1 --conf spark.executor.memory=1g --conf spark.driver.cores=1 --conf spark.driver.memory=1g --conf spark.executor.instances=1"
       }
     }' \
   --configuration-overrides '{
       "monitoringConfiguration": {
       "s3MonitoringConfiguration": {
       "logUri": "s3://{{amzn-s3-demo-bucket}}/logs/"
       }
     }
   }'
   ```

------
#### [ Hive ]

   다음 예제와 같이 `hive.metastore.glue.catalogid` 분류에서 `hive-site` 속성을 설정합니다. {{`AccountB-catalog-id`}}를 `AccountB`의 Data Catalog ID로 바꿉니다.

   ```
   aws emr-serverless start-job-run \
   --application-id "{{application-id}}" \
   --execution-role-arn "{{job-role-arn}}" \
   --job-driver '{
       "hive": {
       "query": "s3://{{amzn-s3-demo-bucket}}/hive/scripts/create_table.sql",
       "parameters": "--hiveconf hive.exec.scratchdir=s3://{{amzn-s3-demo-bucket}}/hive/scratch --hiveconf hive.metastore.warehouse.dir=s3://{{amzn-s3-demo-bucket}}/hive/warehouse"
       }
   }' \
   --configuration-overrides '{
       "applicationConfiguration": [{
           "classification": "hive-site",
           "properties": {
               "hive.metastore.glue.catalogid": "{{AccountB-catalog-id}}"
           }
       }]
   }'
   ```

------

### AWS Glue 데이터 카탈로그 사용 시 고려 사항
<a name="glue-metastore-considerations"></a>

Hive 스크립트에서 `ADD JAR`을 사용하여 보조 JAR을 추가할 수 있습니다. 추가 고려 사항은 [AWS Glue 데이터 카탈로그 사용 시 고려 사항을](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-hive-metastore-glue.html#emr-hive-glue-considerations-hive) 참조하세요.