

# Databricks Unity Catalog

 AWS Context reaches Databricks Unity Catalog through an AWS Glue connection that you create in your AWS account. A Databricks connection covers one Unity Catalog catalog.

## Prerequisites
<a name="databricks-prerequisites"></a>

Set up the following before you create a Databricks connection.
+ An AWS Glue connection of type Databricks to your workspace, in the same AWS account and Region as the AWS Context connection. The AWS Glue connection must be ready and must have an IAM role. For what that IAM role must allow, see [IAM role for the AWS Glue connection](#databricks-glue-connection-role).
+ The IAM principal that calls AWS Context `CreateConnection` needs `glue:CreateCatalog`. See [Permissions for the principal that creates the connection](#databricks-lake-formation-creator).
+ For `ingestionConfig.roleArn`, specify the ingestion role, which AWS Glue assumes to send the connection’s metadata to your Agent Contexts. For the role’s trust policy and permissions policy, see [Ingestion role](#databricks-ingestion-role).

## Ingestion role
<a name="databricks-ingestion-role"></a>

A Databricks connection uses an ingestion role, which AWS Glue assumes to send the connection’s metadata to your Agent Contexts. The ingestion role must be in the same AWS account as the connection. The principal that creates or updates the connection needs `iam:PassRole` for the role, with `glue.amazonaws.com` as the value of `iam:PassedToService` if your policy uses that condition key. A Databricks connection doesn’t use a data access role.

The role’s trust policy must allow the AWS Glue service principal `glue.amazonaws.com` to assume the role. To limit the role to your account, add the condition key `aws:SourceAccount` with your account ID. Replace `111122223333` with your account ID.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": "glue.amazonaws.com" },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": { "aws:SourceAccount": "111122223333" }
      }
    }
  ]
}
```

The role’s permissions policy is the same as for an AWS Glue Data Catalog connection. For the policy, see [Permissions for AWS Glue tables and Amazon S3 Tables](glue-data-catalog-source.md#glue-tables-permissions). That policy includes `glue:SendMetadata` on your account’s root catalog ARN (`arn:aws:glue:{{region}}:111122223333:catalog`), which is required for Databricks connections too. If the role doesn’t allow `glue:SendMetadata`, AWS Glue doesn’t deliver the connection’s metadata to your Agent Contexts and doesn’t report an error. Metadata that AWS Glue skipped isn’t sent again on a later sync, which sends only changes. After you fix the role, delete the connection and create it again so that AWS Glue sends the full catalog. The role needs `kms:Decrypt` if your Data Catalog is encrypted with a customer managed AWS KMS key, even though the metadata comes from Databricks. You can use the same ingestion role for AWS Glue Data Catalog, Databricks, and Snowflake connections.

## IAM role for the AWS Glue connection
<a name="databricks-glue-connection-role"></a>

The AWS Glue connection’s IAM role is the role that the AWS Glue managed crawlers run as when they synchronize assets and lineage from the source. AWS Context also uses it to register the AWS Glue connection with AWS Lake Formation if it isn’t registered yet, and grants the role `DESCRIBE` on the catalog that it creates. You don’t grant AWS Lake Formation permissions to this role yourself.

The role’s trust policy must allow AWS Glue and AWS Lake Formation to assume the role.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": [ "glue.amazonaws.com", "lakeformation.amazonaws.com" ] },
      "Action": "sts:AssumeRole"
    }
  ]
}
```

Give the role the following permissions:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadGlueConnection",
      "Effect": "Allow",
      "Action": "glue:GetConnection",
      "Resource": [
        "arn:aws:glue:us-east-1:111122223333:catalog",
        "arn:aws:glue:us-east-1:111122223333:connection/my-databricks-glue-connection"
      ]
    },
    {
      "Sid": "ReadFederatedCatalog",
      "Effect": "Allow",
      "Action": [
        "glue:GetCatalog",
        "glue:GetCatalogs",
        "glue:GetDatabase",
        "glue:GetDatabases",
        "glue:GetTable",
        "glue:GetTables"
      ],
      "Resource": [
        "arn:aws:glue:us-east-1:111122223333:catalog",
        "arn:aws:glue:us-east-1:111122223333:catalog/*",
        "arn:aws:glue:us-east-1:111122223333:database/*",
        "arn:aws:glue:us-east-1:111122223333:table/*"
      ]
    },
    {
      "Sid": "ReadConnectionSecret",
      "Effect": "Allow",
      "Action": "secretsmanager:GetSecretValue",
      "Resource": "arn:aws:secretsmanager:us-east-1:111122223333:secret:my-databricks-client-secret-AbCdEf"
    },
    {
      "Sid": "PublishLineageEvents",
      "Effect": "Allow",
      "Action": "glue:PostLineageEvent",
      "Resource": "*"
    }
  ]
}
```

Replace the Region `us-east-1`, the account ID `111122223333`, the connection name `my-databricks-glue-connection`, and the secret name `my-databricks-client-secret-AbCdEf` with your own values. If the secret is encrypted with a customer managed AWS KMS key, also add `kms:Decrypt` on the key. `glue:PostLineageEvent` doesn’t support resource-level permissions, so specify `*`. Without `glue:PostLineageEvent`, AWS Glue can’t publish lineage events, so AWS Context doesn’t collect lineage, but asset synchronization still works. The role doesn’t need Amazon S3 permissions.

The principal that creates the AWS Context connection needs permission to register the AWS Glue connection with AWS Lake Formation and to grant permissions on it: `lakeformation:DescribeResource`, `lakeformation:RegisterResource`, and `lakeformation:GrantPermissions`, and `iam:PassRole` for the AWS Glue connection’s role to `lakeformation.amazonaws.com`. Without these permissions, `CreateConnection` is denied.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "RegisterGlueConnectionWithLakeFormation",
      "Effect": "Allow",
      "Action": [
        "lakeformation:DescribeResource",
        "lakeformation:RegisterResource",
        "lakeformation:GrantPermissions"
      ],
      "Resource": "*"
    },
    {
      "Sid": "PassGlueConnectionRole",
      "Effect": "Allow",
      "Action": "iam:PassRole",
      "Resource": "arn:aws:iam::111122223333:role/ContextGlueSourceRole",
      "Condition": {
        "StringEquals": { "iam:PassedToService": "lakeformation.amazonaws.com" }
      }
    }
  ]
}
```

Replace the account ID `111122223333` and the role name `ContextGlueSourceRole` with your own values.

## Permissions for the principal that creates the connection
<a name="databricks-lake-formation-creator"></a>

When you publish a Databricks connection, AWS Context creates a federated catalog in AWS Glue. The IAM principal that calls AWS Context `CreateConnection` needs `glue:CreateCatalog` on two resources: the regional root Glue Data Catalog and the new federated catalog. This IAM requirement also applies to AWS Lake Formation data lake administrators. Permissions on the crawler role or the ingestion role do not grant this access to the caller. See [CreateCatalog](https://docs.aws.amazon.com/service-authorization/latest/reference/list_glue.html#list_glue-action-CreateCatalog) in the *Service Authorization Reference*.

A AWS Lake Formation data lake administrator in the Glue connection’s account and Region already has the required AWS Lake Formation permissions. For any other caller, ask an authorized grantor to grant these AWS Lake Formation permissions without the grant option:
+  `CREATE_CATALOG` on the Data Catalog of the Region. In the AWS Lake Formation console, choose **Catalog creators**, and then choose **Grant**.
+  `DATA_LOCATION_ACCESS` on the ARN of the registered AWS Glue connection. In the AWS Lake Formation console, choose **Permissions**, **Data locations**, and then **Grant**. Grant this permission for each AWS Glue connection that you plan to use.

If you use explicit AWS Lake Formation grants, verify that the grants name the caller and the resources listed above. For more information, see [Prerequisites for connecting the Data Catalog to external data sources](https://docs.aws.amazon.com/lake-formation/latest/dg/connect-data-source-prerequisites.html) in the * AWS Lake Formation Developer Guide*.

## Create a Databricks connection
<a name="databricks-create"></a>

A connection that you create in the console or with the API uses an AWS Glue connection that you create. Whether that connection queries data as each end user depends on the AWS Glue connection, not on how you create the AWS Context connection.

Per-user access to data requires Credential Broker settings on the AWS Glue connection. Without them, AWS Context synchronizes metadata but can’t query the source’s data. The AWS Glue console doesn’t support these settings. To add them, create the AWS Glue connection with the AWS CLI or an AWS SDK (AWS Glue `CreateConnection`). In `ConnectionInput.AuthenticationConfiguration`, set `CredentialBrokerProperties` with `CredentialProviderArn` (the credential provider ARN, in the same account and Region), `OAuth2GrantType` set to `AUTHORIZATION_CODE`, and `Scopes`:

```json
"AuthenticationConfiguration": {
  "CredentialBrokerProperties": {
    "CredentialProviderArn": "arn:aws:credentialbroker:region:111122223333:credentialproviderpool/pool-id/credentialprovider/provider-id",
    "OAuth2GrantType": "AUTHORIZATION_CODE",
    "Scopes": [ "all-apis", "offline_access" ]
  }
}
```

Keep the other authentication settings that the connection type needs, which are the credentials that AWS Glue uses to synchronize metadata. Users must authorize again if you change the scopes. For more information, see [CreateConnection](https://docs.aws.amazon.com/glue/latest/webapi/API_CreateConnection.html) in the * AWS Glue API Reference*.

After the AWS Glue connection has these settings, an AWS Context connection that uses it queries data as each end user, whether you create the AWS Context connection in the console or with the API. For more information, see [Identity and per-user access](#databricks-identity).

**To create a Databricks connection (console)**

1. Open the AWS Context console.

1. In the navigation pane, choose **Connections**.

1. Choose **Create connection**.

1. On the **Choose a data source** page, choose **Databricks**, and then choose **Next**.

1. On the **Configure connection** page, for **Connection name**, keep the generated name or enter a name.

1. Under **Data scope**, in **Available data**, choose what to ingest from one catalog:
   + To ingest the whole catalog, including schemas that are added later, select the catalog.
   + To ingest only some schemas, expand the catalog and select those schemas, or select the catalog and then clear the schemas that you don’t want. Schemas that are added later aren’t included.

      **Available data** lists the Databricks catalogs, and their schemas, that AWS Glue has indexed in the AWS Glue Data Catalog. If no catalog is indexed, the console shows **No Databricks resources in AWS Glue**. To refresh the list, choose the refresh button next to **Available data**. You can’t choose individual tables.

1. (Optional) Add tags to the connection.

   To add tags, you need permission for `context:TagResource` in addition to `context:CreateConnection`. Otherwise, AWS Context denies the request and doesn’t create the connection. For more information, see [Permissions to create tagged resources](tagging-access-control.md#tagging-access-on-create).

1. Choose **Next**.

1. On the **Set permissions** page, for **Ingestion access**, choose the IAM role that AWS Glue assumes to write metadata to your agent contexts.

1. Under **Data access**, in the **Databricks** row, for ** AWS Glue connection**, choose the AWS Glue connection to your Databricks workspace. You can’t choose an AWS Glue connection that isn’t ready or that has no IAM role.

1. Select the check box to confirm that the AWS Glue connection reads the metastore that the console shows.

1. Choose **Next**.

1. On the **Review and create** page, review your choices, and then choose **Create connection**.

The console shows a message that the connection was created and opens the **Connections** page. While AWS Glue sets up catalog synchronization, the connection’s status is **Creating**. While the **Connections** page or the connection’s details page is open, the console continues the setup until the status is **Active** or **Failed**.

**To create a Databricks connection (API)**  
To create a Databricks connection, call `CreateConnection`. For `dataSource.type`, specify `DATABRICKS`. For `dataSource.location.arn`, specify the ARN of the AWS Glue connection. Specify these additional parameters:
+ For `name`, enter 3–63 characters. The name must start with a letter and can contain letters, digits, and hyphens.
+ For `scope`, specify the Unity Catalog catalog to ingest and, optionally, the schemas in it. Each entry of `scope.selectors` has a `path`, a list of segments with a `level` and an `id`. For a Databricks connection, the path starts with a `databricksCatalog` segment, which can be followed by a `databricksSchema` segment. A scope can have up to 100 selectors.
+  `clientToken` is optional (1–64 characters). AWS Context remembers a token for a limited time. For a Databricks connection, AWS Context doesn’t return the original connection when you retry `CreateConnection` with a token that was already used. AWS Context rejects the request. To find the connection, call `GetConnection` or `ListConnections`.
+  `publish` is optional and defaults to `true`.
+ If you specify `tags`, you also need permission for `context:TagResource`. For more information, see [Permissions to create tagged resources](tagging-access-control.md#tagging-access-on-create).

The following JSON example shows the request parameters for `CreateConnection`. Replace *region*, the account ID `111122223333`, and the names with your own values.

```json
{
  "name": "my-databricks-connection",
  "dataSource": {
    "type": "DATABRICKS",
    "location": {
      "arn": "arn:aws:glue:region:111122223333:connection/my-databricks-glue-connection"
    }
  },
  "scope": {
    "selectors": [
      {
        "path": [
          { "level": "databricksCatalog", "id": "main" },
          { "level": "databricksSchema", "id": "sales" }
        ]
      }
    ]
  },
  "ingestionConfig": {
    "roleArn": "arn:aws:iam::111122223333:role/ContextIngestionRole"
  }
}
```

A whole-catalog scope uses one selector with one segment: `{ "path": [ { "level": "databricksCatalog", "id": "main" } ] }`.

 `CreateConnection` returns the connection and its `status`. To read the configuration and status of a connection later, call `GetConnection`. For the status values `CREATING`, `ACTIVE`, `UPDATING`, `DELETING`, and `FAILED`, see [Check connection status](check-connection-status.md).

 AWS Glue starts the first synchronization shortly after it sets up catalog synchronization, so you don’t wait a day for the first run. After that, AWS Glue synchronizes once a day. The first synchronization of a large catalog can take some time.

If setup doesn’t finish within the request, `CreateConnection` returns the connection with the status `CREATING`. `subStatus` shows the last setup step that was reached, for example, `GLUE_CONNECTION_VALIDATED` or `SYNC_JOB_CREATED`. The connection doesn’t continue setup on its own, and `GetConnection` only reports its status. To continue setup, call `UpdateConnection` with `connectionId` and the same `ingestionConfig`, and with no other changes. If you created the connection with `publish` set to `false`, also set `publish` to `true`. Wait between calls, and repeat the call until the status is `ACTIVE` or `FAILED`. Use the same ingestion role in each call. The console does this for you while the **Connections** page or the connection’s details page is open.

The status becomes `FAILED` if AWS Glue can’t validate the AWS Glue connection, if the AWS Glue connection no longer exists or has no IAM role, or if AWS Glue can’t set up catalog synchronization.

If `CreateConnection` returns an error, call `GetConnection` or `ListConnections` to check whether the connection exists. If AWS Context removed the connection, the error message says so; fix the cause, and then call `CreateConnection` again with a new client token. If the connection still exists with the status `CREATING`, fix the cause, and then call `UpdateConnection` as described earlier. If `UpdateConnection` returns an error, the connection remains; fix the cause, and then call `UpdateConnection` again.

If the error identifies `glue:CreateCatalog` and HTTP 403 (access denied), check the caller’s IAM and AWS Lake Formation permissions. See [Permissions for the principal that creates the connection](#databricks-lake-formation-creator).

If `status` is `FAILED`, the response includes `failure` with a `code` and a `message`. The code is `GLUE_CONNECTION_UNAVAILABLE`. AWS Context might add more codes, so handle a code that you don’t recognize. Use `code`, not `message`, in programs. A `FAILED` connection can’t be updated. Delete the connection and create it again.

**Keeping metadata current**  
 `syncSchedule` for a Databricks connection must be `DAILY`, or omit it (the default is `DAILY`). AWS Glue requires an interval of at least one day, so a connection with `HOURLY` fails. AWS Context rejects `WEEKLY`, `MONTHLY`, and cron expressions when you publish the connection.

## Identity and per-user access
<a name="databricks-identity"></a>

Per-user access queries Databricks as the end user who sent the request, instead of with the connection’s shared credentials. AWS Glue obtains each user’s token from an AWS IAM Credential Broker credential provider through the OAuth 2.0 authorization code grant. AWS Context doesn’t pass or store a user’s token. Per-user access depends on the following.
+ Per-user access needs a trusted end-user identity on the request: a session from IAM Identity Center with trusted identity propagation, or an IAM federation session (a SAML or OIDC identity provider with trusted identity propagation turned on). For federated users, the `Subject` type must be `user`. A request without a user identity gets no data from the catalog. For setup, see [IAM Identity Center for workforce users](identity-idc-registration.md) and [SSO federation through corporate IdPs](identity-sso-federation.md).
+ For an IAM Identity Center session that an application creates, the application creates an identity-enhanced role session: it passes the user’s identity context to `AssumeRole` in `ProvidedContexts`, with the context provider ARN `arn:aws:iam::aws:contextProvider/IdentityCenter`. For more information, see [IAM Identity Center for workforce users](identity-idc-registration.md).
+ Per-user access uses an AWS IAM Credential Broker credential provider (OAuth, authorization code grant) in the same AWS account and Region as the connection. You set it on the AWS Glue connection in `CredentialBrokerProperties`, as described earlier in this topic. Add the AWS Context console’s session binding URL (the console URL for the Region, followed by `/session_binding`) to the provider’s allowed session binding URLs. For more information, see [AWS IAM Credential Broker](https://docs.aws.amazon.com/IAM/latest/UserGuide/credential-broker.html), [Obtain a token on behalf of a user with the authorization code grant](https://docs.aws.amazon.com/IAM/latest/UserGuide/credential-broker-3lo.html), and [Understand session binding](https://docs.aws.amazon.com/IAM/latest/UserGuide/credential-broker-session-binding.html) in the *IAM User Guide*.
+ In Databricks, register an OAuth client for the credential provider, with its redirect URL set to the provider’s callback URL, and scopes that include `offline_access` for a refresh token. For more information, see [Enable or disable partner OAuth applications](https://docs.databricks.com/aws/en/integrations/enable-disable-oauth) in the Databricks documentation.
+ Each user signs in once. The first time a request needs this catalog’s data for a user, `AgenticRetrieve` returns `authorizationRequired` with a single-use authorization URL. The user signs in to Databricks there, and Databricks applies that account’s permissions. AWS Context doesn’t map IAM principals to Databricks accounts. For more information, see [Snowflake and Databricks: identity mapping](source-acls-third-party-identity-mapping.md). Until a user completes the one-time sign-in, queries for that user return no rows from the source. Only the AWS Glue crawlers use the connection’s stored credentials. An administrator who hasn’t signed in through the authorization URL can’t browse the catalog’s databases and tables in AWS Glue or query the source. The **Available data** list in the AWS Context console isn’t affected.
+ The IAM principal of each end user needs `glue:GetConnection` on the AWS Glue connection and on the Data Catalog of the account, `glue:ManagedConnector` on `*`, `secretsmanager:GetSecretValue` on the AWS Secrets Manager secret that stores the credential provider’s client secret (and `kms:Decrypt` on a customer managed key), and `credentialbroker:GetOAuthToken`, `credentialbroker:StartOAuthSession`, `credentialbroker:CompleteOAuthSessionBinding`, and `credentialbroker:GetCredentialProvider` on the credential provider. For more information, see [Control access to AWS IAM Credential Broker](https://docs.aws.amazon.com/IAM/latest/UserGuide/credential-broker-permissions.html) in the *IAM User Guide*.

## Metric views
<a name="databricks-metric-views"></a>

 AWS Context ingests metric definitions from metric views in Databricks Unity Catalog. AWS Context ingests the definitions only, not metric values or query results.

Metric views are ingested together with the other metadata of the connection. A connection has no setting that is specific to metric definitions. A metric view is ingested only if the schema that contains it is within the scope of the connection, because the scope selects catalogs or schemas and can’t include or exclude an individual view. If you set data filtering when you add the connection to an Agent Context, the view must also be within that selection. Data filtering treats a metric view as a table: if you filter at the catalog or schema level, the views in the selected schemas are included, and if you choose individual tables, a view is ingested only if you also choose the view itself. In the API, name the view at the `databricksTable` level of `connectionMappings[].pathSegments`.

## Add the connection to an Agent Context
<a name="databricks-add"></a>

A connection must be `ACTIVE` before you can add it to an Agent Context. To ingest only some tables of the catalog into an Agent Context, use data filtering when you add the connection to that Agent Context. In the API, set `connectionMappings[].pathSegments` with the levels `databricksCatalog`, `databricksSchema`, and `databricksTable`. For more information, see [Filters and scoping a connection](filters-and-scoping.md). An Agent Context can have at most 20 connection mappings.

## Change or delete the connection
<a name="databricks-change"></a>

To change the name or the scope of the connection, call `UpdateConnection` with the changed member. `ingestionConfig` is required on every `UpdateConnection` call. You can’t change the data source of a connection.

If the status of the connection doesn’t allow the update, AWS Context rejects the request. Check the status with `GetConnection`.

You can’t change the scope of a Databricks connection while an Agent Context uses the connection. Remove the connection from the Agent Context first.

You can’t delete a connection while an Agent Context still uses it. Remove the connection from every Agent Context, and then call `DeleteConnection`.

## Considerations
<a name="databricks-considerations"></a>

Keep the following in mind for a Databricks connection.
+ A Databricks connection covers one Unity Catalog catalog.
+ An Agent Context can have at most 20 connection mappings.