

# AWS Glue tables and S3 tables

When you connect AWS Glue Data Catalog to AWS Context, agents can find your AWS Glue tables and S3 tables through their metadata and query the data in them.
+  **Metadata** – With auto-discovery turned on, AWS Glue sends the catalog’s databases, tables, and columns to AWS Context by using an ingestion role that you provide. There’s no manual import. A connection that covers a whole catalog or database also covers tables that are created later.
+  **Queries** – Agents query the tables with `ExecuteSql` and agentic retrieval. The data stays where it’s stored. AWS Context doesn’t copy it, so every query reads the current data. These sources don’t need an AWS Glue connection.
+  **Access** – Queries run with the caller’s own credentials or with a data access role that you choose. IAM and AWS Lake Formation permissions determine which tables and data a caller can read.

For AWS Glue Data Catalog tables, AWS Context receives databases, tables, and columns. For each table, it receives the name and description. For each column, it receives the name, data type, description, and whether the column is a partition key.

After you create the connection, add it to one or more Agent Contexts. For more information, see [Create a data mapping](create-a-data-mapping.md).

**Prerequisites**
+ Turn on auto-discovery in AWS Glue for your account. AWS Glue sends metadata to AWS Context only for an account that has auto-discovery turned on. If auto-discovery is turned off for your account, the AWS Context console shows the option to turn it on under **Data scope** when you create a connection.

To connect AWS Glue tables or S3 tables, complete the following steps:

1.  [Set up the ingestion role](#glue-tables-ingestion-role) 

1.  [Choose how AWS Context reads the data](#glue-tables-data-access) 

1.  [Create the connection](#glue-tables-create) 

## Step 1: Set up the ingestion role
<a name="glue-tables-ingestion-role"></a>

The ingestion role (`ingestionConfig.roleArn`) is the role that AWS Glue assumes to send catalog metadata to AWS Context. Every connection requires an ingestion role. The role must be in the same AWS account as the connection. You can use one ingestion role for more than one connection.
+  **Console** – On the **Set permissions** page, the console can create the role for you. Choose **Create and use a new service role** (the default), or choose **Use an existing service role**.
+  **API** – Create the role before you call `CreateConnection`. For the trust policy and the permissions policy, see [Ingestion role](#glue-ingestion-role-permissions).

The principal that creates the connection needs `iam:PassRole` for the ingestion role. In a policy that uses the `iam:PassedToService` condition key, use `glue.amazonaws.com`, because the ingestion role is passed to AWS Glue.

## Step 2: Choose how AWS Context reads the data
<a name="glue-tables-data-access"></a>

Choose one of the following before you create the connection:
+  **Caller credentials** – Omit `accessConfig`. AWS Context reads the source with the caller’s own credentials, so callers reach only what their own IAM permissions allow and, for AWS Glue tables, what their AWS Lake Formation permissions allow. Callers then need IAM permissions on the underlying resources.
+  **Data access role** – Specify `accessConfig.iamRole.roleArn`. AWS Context assumes that role for every caller, so every caller gets the role’s permissions. If agents in AWS Quick access the Agent Context’s data, use a data access role. A connection can have only one data access role.

You can’t add or remove the data access role after you create the connection. To change how a connection reads its data, delete the connection and create it again.

If you map several connections that reach the same table into an Agent Context, AWS Context reads the table through the connection whose mapping you created first, with that connection’s setting. For more information, see [When several connections reach the same data](how-access-controls-apply-when-aws-context-queries-data.md#overlapping-connections).
+  **Console** – On the **Set permissions** page, under **Data access**, choose **Use caller credentials (recommended)** or **Use a data access role**. For AWS Glue tables and S3 tables, the console can create a new data access role, or you can choose an existing role.
+  **API** – If you use a data access role, create it before you call `CreateConnection`. For the trust policy and the permissions policies, see [Data access role](#glue-data-access-role-permissions). The principal that creates the connection needs `iam:PassRole` for the role. In a policy that uses the `iam:PassedToService` condition key, use `context.amazonaws.com`, because the data access role is passed to AWS Context. A policy statement that allows `iam:PassRole` only to AWS Context doesn’t cover the ingestion role.

If you use caller credentials, grant callers the permissions that the data access role would need on the tables.

## Step 3: Create the connection
<a name="glue-tables-create"></a>

To create the connection, an IAM principal needs permission for `context:CreateConnection`, permission to pass each role in the request, and permission to read the Data Catalog. To read the Data Catalog, the principal needs permission for the AWS Glue action `glue:GetCatalog` and, depending on the connection’s scope, for `glue:GetDatabase`, `glue:GetDatabases`, or both.

**To create an AWS Glue Data Catalog 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 ** AWS Glue**, and then choose **Next**.

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

1. Under **Data scope**, for **Data source location**, choose **This AWS account**.

1. Under **Available data**, expand ** AWS Glue**, expand **Catalogs**, expand the default catalog, and then expand **Databases**.

1. Select the databases to include. To include every database in the catalog, including databases that are added later, select the catalog instead.

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, under **IAM permissions**, for **Ingestion role**, choose **Create and use a new service role** (the default) and enter a **Service role name**. To reuse a role, choose **Use an existing service role** and choose the **Ingestion role ARN**.

1. Under **Data access**, choose **Use caller credentials (recommended)** or **Use a data access role**. If you choose a data access role, choose a role for each data source type in the table.

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. The connection’s status is **Active**.

**To create an AWS Glue Data Catalog connection (API)**  
This procedure connects a Data Catalog in your own account. To create the connection, call `CreateConnection`. Specify `name`; `dataSource` (`type` is `GLUE_DATA_CATALOG`, `location.arn` is the catalog ARN); and `ingestionConfig.roleArn`. Optionally specify `accessConfig.iamRole.roleArn`, `scope`, and `clientToken`. If you omit `accessConfig`, AWS Context queries the data with the caller’s own credentials.

The following JSON example shows the request parameters that create the connection. Replace *region*, the account ID `111122223333`, and the role names with your own values.

```json
{
  "name": "sales-catalog",
  "dataSource": {
    "type": "GLUE_DATA_CATALOG",
    "location": { "arn": "arn:aws:glue:region:111122223333:catalog" }
  },
  "scope": {
    "selectors": [
      { "path": [ { "level": "glueService", "id": "GLUE" } ] }
    ]
  },
  "accessConfig": { "iamRole": { "roleArn": "arn:aws:iam::111122223333:role/data-access-role-name" } },
  "ingestionConfig": { "roleArn": "arn:aws:iam::111122223333:role/ingestion-role-name" }
}
```

A connection name has 3–63 characters, starts with a letter, and contains only letters, digits, and hyphens.

For `dataSource.location.arn`, specify one of the following catalog ARNs. Replace *region*, the account ID `111122223333`, and the table bucket name `amzn-s3-demo-table-bucket` with your own values:
+ The default catalog: `arn:aws:glue:{{region}}:111122223333:catalog` 
+ An S3 Tables catalog: `arn:aws:glue:{{region}}:111122223333:catalog/s3tablescatalog/amzn-s3-demo-table-bucket` 

Before it saves the connection, AWS Context reads the Data Catalog with your permissions. It doesn’t check tables. AWS Context rejects the request and doesn’t create the connection if any of the following is true: you aren’t allowed to pass a role, AWS Glue denies the read, or the catalog or a selected database isn’t found. A successful `CreateConnection` request doesn’t confirm that the roles' trust policies and permissions policies are complete.

When `CreateConnection` succeeds, the connection is `ACTIVE`. `ACTIVE` means that the connection was created, not that metadata has been ingested.

## Permissions for AWS Glue tables and S3 tables
<a name="glue-tables-permissions"></a>

An AWS Glue Data Catalog connection uses an ingestion role, which AWS Glue assumes, and an optional data access role, which AWS Context assumes. Each role’s trust policy must allow the service that assumes the role. Create both roles in the same AWS account as the connection; AWS Context rejects a role in another account. Specify each role by its Amazon Resource Name (ARN), which can include a path.
<a name="glue-ingestion-role-permissions"></a>
**Ingestion role**  
 `ingestionConfig.roleArn` names the ingestion role, which AWS Glue assumes to send Data Catalog metadata to AWS Context. The same ingestion role works for all three categories of AWS native structured sources, including Amazon DynamoDB connections. When AWS Glue assumes the role, it names a Data Catalog ARN as the source: the account’s root catalog, or an S3 Tables catalog. The trust policy that follows allows both. You can use one ingestion role for more than one connection.

The ingestion role’s trust policy must allow the AWS Glue service principal `glue.amazonaws.com` to assume the role.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowGlueToAssumeRole",
      "Effect": "Allow",
      "Principal": { "Service": "glue.amazonaws.com" },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": { "aws:SourceAccount": "111122223333" },
        "ArnLike": {
          "aws:SourceArn": [
            "arn:aws:glue:us-east-1:111122223333:catalog",
            "arn:aws:glue:us-east-1:111122223333:catalog/*"
          ]
        }
      }
    }
  ]
}
```

Replace the Region `us-east-1` and the account ID `111122223333` with your own values.

Attach a permissions policy to the ingestion role that allows the role to send your catalog’s metadata into your Agent Contexts. The role needs `context:IngestAgentContext`, limited to sources in your account, and `glue:SendMetadata` on your Data Catalog. If the ingestion role doesn’t have `glue:SendMetadata`, AWS Glue sends no metadata to the Agent Contexts that use the connection. No error is reported. If your Data Catalog is encrypted with a customer managed AWS KMS key, the role also needs `kms:Decrypt` on that key. The key policy must allow the role to use the key. The following policy applies to AWS Glue Data Catalog, Databricks, and Snowflake connections. Omit the `DecryptCatalogMetadata` statement if your Data Catalog isn’t encrypted with a customer managed key.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "IngestFromGlueDataCatalog",
      "Effect": "Allow",
      "Action": "context:IngestAgentContext",
      "Resource": "*",
      "Condition": {
        "ArnLike": {
          "context:SourceArn": [
            "arn:aws:glue:us-east-1:111122223333:catalog",
            "arn:aws:glue:us-east-1:111122223333:catalog/*",
            "arn:aws:glue:us-east-1:111122223333:connection/*"
          ]
        },
        "StringEquals": { "aws:ResourceAccount": "${aws:PrincipalAccount}" }
      }
    },
    {
      "Sid": "SendGlueMetadata",
      "Effect": "Allow",
      "Action": "glue:SendMetadata",
      "Resource": "arn:aws:glue:us-east-1:111122223333:catalog"
    },
    {
      "Sid": "DecryptCatalogMetadata",
      "Effect": "Allow",
      "Action": "kms:Decrypt",
      "Resource": "arn:aws:kms:us-east-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
    }
  ]
}
```

Replace the Region `us-east-1`, the account ID `111122223333`, and the key ID `1234abcd-12ab-34cd-56ef-1234567890ab` with your own values. Keep `${aws:PrincipalAccount}` as is; it is an IAM policy variable.
<a name="glue-data-access-role-permissions"></a>
**Data access role (optional)**  
 AWS Context assumes the data access role to read the connection’s data source. The data access role’s trust policy must allow the AWS Context service principal, `context.amazonaws.com`, to perform `sts:AssumeRole`. To limit the role to your account, you can add the condition keys `aws:SourceAccount`, with your account ID, and `aws:SourceArn`, with an `ArnLike` pattern such as `arn:aws:context:{{region}}:111122223333:*`. Replace *region* and the account ID `111122223333` with your own values.

If your users sign in through IAM Identity Center and your instance uses the legacy experience of trusted identity propagation, the trust policy must also allow `sts:SetContext`. If your users sign in with any method that carries a user identity, allow `sts:SetContext` as well. For more information, see [Control TIP for IAM federation with IAM policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_tip_federation_policies.html) in the *IAM User Guide* and [Legacy experience of trusted identity propagation](https://docs.aws.amazon.com/singlesignon/latest/userguide/tip-legacy-experience.html) in the *IAM Identity Center User Guide*.

When you omit the data access role, a session from an IAM Identity Center instance that uses the legacy experience of trusted identity propagation can’t read AWS Glue Data Catalog tables. AWS Context then tells the caller to turn on the simplified experience. For how to set up trusted identity propagation, see [IAM Identity Center for workforce users](identity-idc-registration.md).

The following trust policy lets AWS Context assume the data access role and add the user’s identity to the role session.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowAWSContextToAssumeRole",
      "Effect": "Allow",
      "Principal": { "Service": "context.amazonaws.com" },
      "Action": [ "sts:AssumeRole", "sts:SetContext" ],
      "Condition": {
        "StringEquals": { "aws:SourceAccount": "111122223333" },
        "ArnLike": { "aws:SourceArn": "arn:aws:context:us-east-1:111122223333:*" }
      }
    }
  ]
}
```

Replace the Region `us-east-1` and the account ID `111122223333` with your own values.

Grant the data access role permission to read the tables that agents can query. Depending on how the tables are governed, this can include permissions in AWS Glue, AWS Lake Formation, and Amazon S3.

The following permissions policy lets the data access role read AWS Glue tables whose data is in Amazon S3 general purpose buckets.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadGlueTable",
      "Effect": "Allow",
      "Action": [ "glue:GetTable", "glue:GetPartitions" ],
      "Resource": [
        "arn:aws:glue:us-east-1:111122223333:catalog",
        "arn:aws:glue:us-east-1:111122223333:database/sales_db",
        "arn:aws:glue:us-east-1:111122223333:table/sales_db/*"
      ]
    },
    {
      "Sid": "ReadTableData",
      "Effect": "Allow",
      "Action": [ "s3:ListBucket", "s3:GetObject" ],
      "Resource": [
        "arn:aws:s3:::amzn-s3-demo-bucket",
        "arn:aws:s3:::amzn-s3-demo-bucket/*"
      ],
      "Condition": { "StringEquals": { "aws:ResourceAccount": "111122223333" } }
    },
    {
      "Sid": "GetLakeFormationDataAccess",
      "Effect": "Allow",
      "Action": "lakeformation:GetDataAccess",
      "Resource": "*"
    }
  ]
}
```

Replace the Region `us-east-1`, the account ID `111122223333`, the database name `sales_db`, and the bucket name `amzn-s3-demo-bucket` with your own values.

The following permissions policy lets the data access role read S3 tables.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadS3TablesCatalog",
      "Effect": "Allow",
      "Action": "glue:GetTable",
      "Resource": [
        "arn:aws:glue:us-east-1:111122223333:catalog",
        "arn:aws:glue:us-east-1:111122223333:catalog/s3tablescatalog",
        "arn:aws:glue:us-east-1:111122223333:catalog/s3tablescatalog/amzn-s3-demo-table-bucket",
        "arn:aws:glue:us-east-1:111122223333:database/s3tablescatalog/amzn-s3-demo-table-bucket/*",
        "arn:aws:glue:us-east-1:111122223333:table/s3tablescatalog/amzn-s3-demo-table-bucket/*"
      ]
    },
    {
      "Sid": "ReadS3TableBucket",
      "Effect": "Allow",
      "Action": [
        "s3tables:GetTableBucket",
        "s3tables:GetNamespace",
        "s3tables:GetTable",
        "s3tables:GetTableMetadataLocation",
        "s3tables:GetTableData"
      ],
      "Resource": [
        "arn:aws:s3tables:us-east-1:111122223333:bucket/amzn-s3-demo-table-bucket",
        "arn:aws:s3tables:us-east-1:111122223333:bucket/amzn-s3-demo-table-bucket/table/*"
      ]
    },
    {
      "Sid": "GetLakeFormationDataAccess",
      "Effect": "Allow",
      "Action": "lakeformation:GetDataAccess",
      "Resource": "*"
    }
  ]
}
```

Replace the Region `us-east-1`, the account ID `111122223333`, and the table bucket name `amzn-s3-demo-table-bucket` with your own values.

 `lakeformation:GetDataAccess` doesn’t support resource-level permissions, so specify `*` as the resource. If AWS Lake Formation governs the tables, also grant the data access role Lake Formation permissions on them. If you use caller credentials instead of a data access role, grant callers the equivalent permissions on the tables.

For Amazon Redshift, Amazon Aurora, and Amazon RDS databases, see [Step 3: Set up the IAM roles](aurora-redshift-rds-source.md#db-data-access-role). For information about access control for S3 tables in the Data Catalog, see [Integrating Amazon S3 Tables with AWS analytics services](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-integrating-aws.html) in the *Amazon S3 User Guide*.

**Related information**
+  [Filters and scoping a connection](filters-and-scoping.md) 
+  [Integrating Amazon S3 Tables with AWS analytics services](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-integrating-aws.html) in the *Amazon S3 User Guide* 