> [!WARNING]
>
> **Preview**
>
>
> This product or feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section
> of the [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA products and features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

A schema registry is a repository for managing schemas used by your
Kafka producers and consumers.

This document shows you how to create a schema registry resource within
Managed Service for Apache Kafka using the
Google Cloud console, the Google Cloud CLI, or the Managed Kafka API.

## Before you begin

Before you create a schema registry, complete the following:

- [Create a Managed Service for Apache Kafka cluster](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/create-cluster.md.txt) in the same region where you are planning to create a schema registry.

### Required roles and permissions


To get the permissions that
you need to create a schema registry,

ask your administrator to grant you the
[Managed Kafka Schema Registry Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/managedkafka.md.txt#managedkafka.schemaRegistryEditor) (`roles/managedkafka.schemaRegistryEditor`) IAM role on your project.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


This predefined role contains

the permissions required to create a schema registry. To see the exact permissions that are
required, expand the **Required permissions** section:


#### Required permissions

The following permissions are required to create a schema registry:

- Grant this permission on the parent location: `managedkafka.schemaRegistries.create`


You might also be able to get
these permissions
with [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or
other [predefined roles](https://docs.cloud.google.com/iam/docs/roles-overview.md.txt#predefined).

## Create a schema registry

### Console

1. In the Google Cloud console, go to the **Schema registries** page.

   [Go to schema registries](https://console.cloud.google.com/managedkafka/schemaRegistries)

   The **Schema registries** page opens.
2. On the **Schema registries** page, click **Create** .

   The **Create Schema registry** page opens.
3. For **Schema registry name** , enter a unique identifier for your registry.

   The name must start with a letter, contain only letters (a-z, A-Z),
   numbers (0-9), and underscores (_), and be 63 characters or less.
4. Select or enter a **Region** from the menu.

   You must already have a single or multiple active Managed Service for Apache Kafka
   clusters in the region specified. To check the regions of your clusters, see
   the documentation about
   [listing your clusters](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/list-clusters.md.txt#list).

   For a list of supported locations, see
   [Managed Service for Apache Kafka locations](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/locations.md.txt).
5. Click **Create**.

### gcloud

1.
   [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

   After installation,
   [initialize](https://docs.cloud.google.com/sdk/docs/initializing) the Google Cloud CLI by running the following command:

   ```bash
   gcloud init
   ```


   If you're using an external identity provider (IdP), you must first
   [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud.md.txt).
2. Use the [`gcloud beta managed-kafka schema-registries create`](https://docs.cloud.google.com/sdk/gcloud/reference/beta/managed-kafka/schema-registries/create) command to create a schema registry:

   <br />

   ```bash
   gcloud beta managed-kafka schema-registries create SCHEMA_REGISTRY_ID \
       --location=LOCATION \
   ```

   Replace the following:
   - <var translate="no">SCHEMA_REGISTRY_ID</var> (required): a unique identifier for your new schema registry. This forms part of the registry's resource name. The name must start with a letter, contain only letters (a-z, A-Z), numbers (0-9), and underscores (_), and be 63 characters or less.
   - <var translate="no">LOCATION</var> (required): the Google Cloud region where the schema registry is going to be created. This location must match the region of the Managed Service for Apache Kafka cluster or clusters using this registry. For supported locations, see [Managed Service for Apache Kafka locations](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/locations.md.txt).

   To create a schema registry named `test_schema_registry`
   in the `us-central1` region, run the following command:

   ```bash
   gcloud beta managed-kafka schema-registries create test_schema_registry \
       --location=us-central1
   ```

   After the command completes successfully, the schema registry is created.
   You can then configure Kafka clients to use its URL. To view the schema
   registry URL, see
   [Schema registry page details](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/schema-registry/view-schema-registry.md.txt#schema-registry-page-details).

### REST

To create a schema registry instance using the REST API, perform the
following steps.

1. Send a `POST` request similar to the following:

```
POST https://managedkafka.googleapis.com/v1main/projects/PROJECT_ID/locations/LOCATION/schemaRegistries
Authorization: Bearer $(gcloud auth application-default print-access-token)
Content-Type: application/json --data @response-body.json
```
2. Create a JSON file `request-body.json` with the following structure:

```json
{
  "schemaRegistryId": "SCHEMA_REGISTRY_ID"
}
```
3. Replace the following:
   - <var translate="no">SCHEMA_REGISTRY_ID</var> (required): a unique identifier for your new schema registry. This forms part of the registry's resource name. The name must start with a letter, contain only letters (a-z, A-Z), numbers (0-9), and underscores (_), and be 63 characters or less.
4. Run the `POST` request with the constructed URI, headers, and body. If successful, the API returns a `200 OK` status code and a response body containing the JSON representation of the newly created SchemaRegistry resource.
5. The following is a sample successful response.

```json
{
  "name": "projects/testing-311516/locations/us-central1/schemaRegistries/test",
  "contexts": [
    "projects/testing-311516/locations/us-central1/schemaRegistries/test/contexts/."
  ]
}
```
6. The `projects/testing-311516/locations/us-central1/schemaRegistries/test/contexts/.` represents the default context. Resources in the default context don't require any context to be specified.
7. For more information, see the [REST API documentation](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/reference/rest.md.txt).

<br />

## What's next

- [List all schema registries](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/schema-registry/list-schema-registries.md.txt)

- [View a schema registry](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/schema-registry/view-schema-registry.md.txt)

- [Create a subject](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/schema-registry/create-subject-version-one.md.txt)

- [Delete a schema registry](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/schema-registry/delete-schema-registry.md.txt)

*Apache Kafka® is a registered
trademark of The Apache Software Foundation or its affiliates in the United
States and/or other countries.*