

# Managing an external catalog integration

After you turn on sync for a federated catalog, you manage it through the catalog with the `UpdateCatalog` and `GetCatalog` operations. This topic shows how to read the sync status and change how often the sync runs. It also shows how to turn sync off, turn on lineage sync for Snowflake and Databricks, and delete a federated catalog. For instructions on creating a federated catalog and turning on sync, see [Integrating with Databricks Unity Catalog](catalog-external-catalogs-databricks.md) and [Integrating with Snowflake Horizon Catalog](catalog-external-catalogs-snowflake.md).

## SyncConfiguration reference
<a name="catalog-external-catalogs-manage-reference"></a>

You turn on and configure sync by adding a `SyncConfiguration` to the `FederatedCatalog` of a catalog. The following example shows the shape of a `SyncConfiguration`:

```json
"SyncConfiguration": {
    "RoleArn": "arn:aws:iam::{{account-id}}:role/{{role-name}}",
    "AssetsSyncConfiguration": { "Status": "ENABLED", "RefreshIntervalMinutes": 1440 },
    "LineageSyncConfiguration": { "Status": "DISABLED" }
}
```

The following table describes the fields and the rules for each one.


**SyncConfiguration fields**  

| Field | Rule | 
| --- | --- | 
| RoleArn | Required. The Amazon Resource Name (ARN) of the IAM role that the managed crawler runs as. The role must be in your account, and AWS Glue must be able to assume it for this catalog. | 
| Status | Either ENABLED or DISABLED. Appears in both AssetsSyncConfiguration and LineageSyncConfiguration. | 
| RefreshIntervalMinutes | Required when the status is ENABLED. Sets how often the managed crawler runs. Use 1440 for a 24-hour interval or 10080 for a 7-day interval. | 
| ManagedCrawlerDetails | Set by AWS Glue and read-only. Holds the crawler ARN, the status (PROVISIONING, PROVISIONED, or FAILED), and any error. You can't set this field. | 
| LineageSyncConfiguration | Optional. Turns on lineage sync. Supported for both Snowflake and Databricks catalogs. For more information, see [Turn on lineage sync](#catalog-external-catalogs-manage-lineage). | 

Sync works only for the `DATABRICKS` and `SNOWFLAKE` connection types. Whenever you send a `CatalogInput`, always include `CreateTableDefaultPermissions` and `CreateDatabaseDefaultPermissions` as empty lists.

## View sync status
<a name="catalog-external-catalogs-manage-status"></a>

The `GetCatalog` operation returns the full catalog, including the managed crawler details. To read the status of the assets managed crawler, run `get-catalog` and narrow the output with the `--query` parameter.

1. Create a request file named `get-catalog.json`.

   ```json
   {
       "CatalogId": "{{account-id}}:{{catalog-name}}"
   }
   ```

1. Run the `get-catalog` command.

   ```bash
   aws glue get-catalog \
       --cli-input-json file://get-catalog.json \
       --query 'Catalog.FederatedCatalog.SyncConfiguration.AssetsSyncConfiguration.ManagedCrawlerDetails'
   ```

   The command returns the crawler ARN and status.

   ```json
   {
       "CrawlerArn": "arn:aws:glue:{{region}}:{{account-id}}:crawler/catalog-sync-assets-{{id}}",
       "Status": "PROVISIONED"
   }
   ```

The managed crawler takes about 20 seconds to reach `PROVISIONED` after you turn on sync. After the crawler reaches `PROVISIONED`, the first crawl starts automatically. The `GetCatalogs` operation lists your catalogs but leaves out the managed crawler status, so use `GetCatalog` for one catalog when you need the crawler status.

## Change the refresh interval
<a name="catalog-external-catalogs-manage-interval"></a>

The refresh interval sets how often the managed crawler runs. To change it, update `RefreshIntervalMinutes` on the catalog with the `UpdateCatalog` operation. Use `1440` for a 24-hour interval or `10080` for a 7-day interval.

1. Create a request file named `update-interval.json`. Include `ConnectionName` and `ConnectionType` so that the update keeps the federated catalog settings.

   ```json
   {
       "CatalogId": "{{account-id}}:{{catalog-name}}",
       "CatalogInput": {
           "CreateTableDefaultPermissions": [],
           "CreateDatabaseDefaultPermissions": [],
           "FederatedCatalog": {
               "ConnectionName": "{{connection-name}}",
               "ConnectionType": "DATABRICKS",
               "SyncConfiguration": {
                   "RoleArn": "{{role-arn}}",
                   "AssetsSyncConfiguration": { "Status": "ENABLED", "RefreshIntervalMinutes": 10080 }
               }
           }
       }
   }
   ```

1. Run the `update-catalog` command.

   ```bash
   aws glue update-catalog --cli-input-json file://update-interval.json
   ```

## Turn sync off
<a name="catalog-external-catalogs-manage-off"></a>

To turn off metadata sync, set the `Status` of `AssetsSyncConfiguration` to `DISABLED` with the `UpdateCatalog` operation. AWS Glue removes the managed crawler, and `GetCatalog` no longer returns the managed crawler details while the `Status` is `DISABLED`.

1. Create a request file named `disable-sync.json`.

   ```json
   {
       "CatalogId": "{{account-id}}:{{catalog-name}}",
       "CatalogInput": {
           "CreateTableDefaultPermissions": [],
           "CreateDatabaseDefaultPermissions": [],
           "FederatedCatalog": {
               "ConnectionName": "{{connection-name}}",
               "ConnectionType": "DATABRICKS",
               "SyncConfiguration": {
                   "RoleArn": "{{role-arn}}",
                   "AssetsSyncConfiguration": { "Status": "DISABLED" }
               }
           }
       }
   }
   ```

1. Run the `update-catalog` command.

   ```bash
   aws glue update-catalog --cli-input-json file://disable-sync.json
   ```

## Rules for updating a federated catalog
<a name="catalog-external-catalogs-manage-update-rules"></a>

When you update a federated catalog, follow these rules so that the update keeps the catalog valid.
+ Always include `ConnectionName` and `ConnectionType` in the `FederatedCatalog`.
+ If you leave out `SyncConfiguration`, the current sync settings stay in place.
+ Always send `CreateTableDefaultPermissions` and `CreateDatabaseDefaultPermissions` as empty lists.

## Turn on lineage sync
<a name="catalog-external-catalogs-manage-lineage"></a>

For a Snowflake or Databricks federated catalog, you can turn on lineage sync by adding a `LineageSyncConfiguration` to the `SyncConfiguration`. When lineage sync is on, AWS Glue creates a second managed crawler for lineage. For a Snowflake catalog, the connection must use a host in the `orgname-accountname.snowflakecomputing.com` format. A Snowflake connection that uses the account locator host is rejected for lineage. For more information about what lineage captures and how to read it, see [Lineage from Snowflake](catalog-lineage-snowflake.md) and [Lineage from Databricks Unity Catalog](catalog-lineage-databricks.md).

1. Create a request file named `enable-lineage.json`. The following example uses a Snowflake catalog. For a Databricks catalog, set `ConnectionType` to `DATABRICKS`.

   ```json
   {
       "CatalogId": "{{account-id}}:{{catalog-name}}",
       "CatalogInput": {
           "CreateTableDefaultPermissions": [],
           "CreateDatabaseDefaultPermissions": [],
           "FederatedCatalog": {
               "ConnectionName": "{{connection-name}}",
               "ConnectionType": "SNOWFLAKE",
               "SyncConfiguration": {
                   "RoleArn": "{{role-arn}}",
                   "AssetsSyncConfiguration": { "Status": "ENABLED", "RefreshIntervalMinutes": 1440 },
                   "LineageSyncConfiguration": { "Status": "ENABLED" }
               }
           }
       }
   }
   ```

1. Run the `update-catalog` command.

   ```bash
   aws glue update-catalog --cli-input-json file://enable-lineage.json
   ```

1. Read the status of the lineage managed crawler with the `get-catalog` command.

   ```bash
   aws glue get-catalog \
       --cli-input-json file://get-catalog.json \
       --query 'Catalog.FederatedCatalog.SyncConfiguration.LineageSyncConfiguration.ManagedCrawlerDetails'
   ```

## Delete a federated catalog and clean up resources
<a name="catalog-external-catalogs-manage-delete"></a>

To remove a federated catalog and the resources you created for it, delete the resources in the following order. Deregister the connection from Lake Formation before you delete the connection.

1. Delete the catalog. This also removes the managed crawler.

   ```bash
   aws glue delete-catalog \
       --catalog-id {{account-id}}:{{catalog-name}}
   ```

1. Deregister the connection from Lake Formation.

   ```bash
   aws lakeformation deregister-resource \
       --resource-arn {{connection-arn}}
   ```

1. Delete the connection.

   ```bash
   aws glue delete-connection \
       --catalog-id {{account-id}} \
       --connection-name {{connection-name}}
   ```

1. Delete the Secrets Manager secret. Deleting a connection doesn't delete its secret.

   ```bash
   aws secretsmanager delete-secret \
       --secret-id {{secret-arn}}
   ```