

# 스키마 생성
<a name="schema-registry-gs4"></a>

AWS Glue API 또는 AWS Glue 콘솔을 사용하여 스키마를 생성할 수 있습니다.

**AWS Glue API**  
다음 단계를 사용하여 AWS Glue API로 이 태스크를 수행할 수 있습니다.

새 스키마를 추가하려면 [CreateSchema 작업(Python: create\_schema)](aws-glue-api-schema-registry-api.md#aws-glue-api-schema-registry-api-CreateSchema) API를 사용합니다.

스키마에 대한 레지스트리를 나타내려면 `RegistryId` 구조를 지정합니다. 또는 기본 레지스트리를 사용하려면 `RegistryId`를 생략합니다.

문자, 숫자, 하이픈, 밑줄로 구성된 `SchemaName`을 지정하고 `DataFormat`은 **AVRO** 또는 **JSON**으로 지정합니다. `DataFormat`은 스키마에 한 번 설정되면 변경할 수 없습니다.

`Compatibility` 모드를 지정합니다.
+ [*뒤로(권장)(Backward (recommended))*] - 소비자가 현재 버전과 이전 버전을 모두 읽을 수 있습니다.
+ [*모두 뒤로(Backward all)*] - 소비자가 현재 및 모든 이전 버전을 읽을 수 있습니다.
+ [*앞으로(Forward)*] - 소비자가 현재 및 후속 버전을 모두 읽을 수 있습니다.
+ [*모두 앞으로(Forward all)*] - 소비자가 현재 버전과 모든 후속 버전을 읽을 수 있습니다.
+ [*전체(Full)*] - 뒤로 및 앞으로의 조합입니다.
+ [*모두 전체(Full all)*] - 모두 뒤로 및 모두 앞으로의 조합입니다.
+ [*없음(None)*] - 호환성 확인이 수행되지 않습니다.
+ [*사용 중지됨(Disabled)*] - 이 스키마에 대한 버전 관리를 방지합니다.

선택적으로 스키마에 `Tags`를 지정합니다.

Avro, JSON 또는 Protobuf 데이터 포맷으로 스키마를 정의하려면 `SchemaDefinition`을(를) 지정합니다. 예제를 참조하세요.

Avro 데이터 포맷의 경우:

```
aws glue create-schema --registry-id RegistryName="registryName1" --schema-name testschema --compatibility NONE --data-format AVRO --schema-definition "{\"type\": \"record\", \"name\": \"r1\", \"fields\": [ {\"name\": \"f1\", \"type\": \"int\"}, {\"name\": \"f2\", \"type\": \"string\"} ]}"
```

```
aws glue create-schema --registry-id RegistryArn="arn:aws:glue:us-east-2:901234567890:registry/registryName1" --schema-name testschema --compatibility NONE --data-format AVRO  --schema-definition "{\"type\": \"record\", \"name\": \"r1\", \"fields\": [ {\"name\": \"f1\", \"type\": \"int\"}, {\"name\": \"f2\", \"type\": \"string\"} ]}"
```

JSON 데이터 포맷의 경우:

```
aws glue create-schema --registry-id RegistryName="registryName" --schema-name testSchemaJson --compatibility NONE --data-format JSON --schema-definition "{\"$schema\": \"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"properties\":{\"f1\":{\"type\":\"string\"}}}"
```

```
aws glue create-schema --registry-id RegistryArn="arn:aws:glue:us-east-2:901234567890:registry/registryName" --schema-name testSchemaJson --compatibility NONE --data-format JSON --schema-definition "{\"$schema\": \"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"properties\":{\"f1\":{\"type\":\"string\"}}}"
```

Protobuf 데이터 형식의 경우:

```
aws glue create-schema --registry-id RegistryName="registryName" --schema-name testSchemaProtobuf --compatibility NONE --data-format PROTOBUF --schema-definition "syntax = \"proto2\";package org.test;message Basic { optional int32 basic = 1;}"
```

```
aws glue create-schema --registry-id RegistryArn="arn:aws:glue:us-east-2:901234567890:registry/registryName" --schema-name testSchemaProtobuf --compatibility NONE --data-format PROTOBUF --schema-definition "syntax = \"proto2\";package org.test;message Basic { optional int32 basic = 1;}"
```

**AWS Glue 콘솔**  
AWS Glue 콘솔을 사용하여 새 스키마를 추가하려면

1. AWS 관리 콘솔에 로그인하여 [https://console.aws.amazon.com/glue/](https://console.aws.amazon.com/glue\)에서 AWS Glue 콘솔을 엽니다.

1. 탐색 창의 [**데이터 카탈로그(Data catalog)**]에서 [**스키마(Schemas)**]를 선택합니다.

1. [**스키마 추가(Add schema)**]를 선택합니다.

1. 문자, 숫자, 하이픈, 밑줄, 달러 기호 또는 해시마크로 구성된 [**스키마 이름(Schema name)**]을 입력합니다. 이 이름은 변경할 수 없습니다.

1. 드롭다운 메뉴에서 스키마가 저장될 [**레지스트리(Registry)**]를 선택합니다. 상위 레지스트리는 생성 후에 변경할 수 없습니다.

1. [**데이터 포맷(Data format)**]을 [*Apache Avro*] 또는 [*JSON*]으로 둡니다. 이 포맷은 이 스키마의 모든 버전에 적용됩니다.

1. [**호환성 모드(Compatibility mode)**]를 선택합니다.
   + [*뒤로(권장)(Backward (recommended))*] - 수신자가 현재 버전과 이전 버전을 모두 읽을 수 있습니다.
   + [*모두 뒤로(Backward All)*] - 수신자가 현재 및 모든 이전 버전을 읽을 수 있습니다.
   + [*앞으로(Forward)*] - 발신자가 현재 버전과 이전 버전을 모두 쓸 수 있습니다.
   + [*모두 앞으로(Forward All)*] - 발신자가 현재 버전과 모든 이전 버전을 모두 쓸 수 있습니다.
   + [*전체(Full)*] - 뒤로 및 앞으로의 조합입니다.
   + [*모두 전체(Full All)*] - 모두 뒤로 및 모두 앞으로의 조합입니다.
   + [*없음(None)*] - 호환성 확인이 수행되지 않습니다.
   + [*사용 중지됨(Disabled)*] - 이 스키마에 대한 버전 관리를 방지합니다.

1. 최대 250자의 레지스트리에 대한 선택적 [**설명(Description)**]을 입력합니다.  
![스키마 생성의 예.](http://docs.aws.amazon.com/ko_kr/glue/latest/dg/images/schema_reg_create_schema.png)

1. 선택적으로 스키마에 하나 이상의 태그를 적용합니다. [**새 태그 추가(Add new tag)**]를 선택하고 [**태그 키(Tag key)**]와 [**태그 값(Tag value)**](선택 사항)을 지정합니다.

1. [**첫 번째 스키마 버전(First schema version)**] 상자에 초기 스키마를 입력하거나 붙여넣습니다.

   Avro 포맷은 [Avro 데이터 포맷 작업](#schema-registry-avro) 섹션을 참조하세요.

   JSON 포맷은 [JSON 데이터 포맷 작업](#schema-registry-json) 섹션을 참조하세요.

1. 선택적으로 [**메타데이터 추가(Add metadata)**]를 선택하여 스키마 버전에 주석을 달거나 분류할 버전 메타데이터를 추가합니다.

1. [**스키마 및 버전 생성(Create schema and version)**]을 선택합니다.

![스키마 생성의 예.](http://docs.aws.amazon.com/ko_kr/glue/latest/dg/images/schema_reg_create_schema2.png)


스키마가 생성되고 [**스키마(Schemas)**] 아래의 목록에 나타납니다.

## Avro 데이터 포맷 작업
<a name="schema-registry-avro"></a>

Avro는 데이터 직렬화 및 데이터 교환 서비스를 제공합니다. Avro는 데이터 정의를 JSON 포맷으로 저장하므로 읽고 해석하기 쉽습니다. 데이터 자체는 바이너리 포맷으로 저장됩니다.

Apache Avro 스키마 정의에 대한 자세한 내용은 [Apache Avro 사양](http://avro.apache.org/docs/current/spec.html)을 참조하세요.

## JSON 데이터 포맷 작업
<a name="schema-registry-json"></a>

데이터는 JSON 포맷으로 직렬화 할 수 있습니다. [JSON 스키마 포맷](https://json-schema.org/)은 JSON 스키마 포맷의 표준을 정의합니다.