Set up the connection in the Agent Context account
In the Agent Context account, create the roles and the connection. The roles must be in the same account as the connection. If the connection uses the caller’s credentials, skip the steps that create the data access role. Attach the permissions policies to the caller’s IAM role instead.
AWS Glue Data Catalog sources
For AWS Glue Data Catalog sources, create a data access role (optional) and an ingestion role. In the following examples, ContextQueryRole is the identity that reads the source: the caller’s IAM role or the connection’s data access role (see Cross-account access). The examples use 111122223333 for the source account, 444455556666 for the Agent Context account, and us-east-1 for the Region. Replace these values and the resource names with your own.
For sources that are metadata only (see When to use cross-account access), AWS Context ingests metadata from the source account’s AWS Glue Data Catalog. For these sources, that identity needs only permission to read the source account’s catalog (see Permissions for metadata-only sources), not permissions for the services themselves. Sources that support real-time retrieval need the permissions policies that follow these steps.
To set up the connection, complete the following steps:
-
(Optional) Create the data access role with the following trust policy. The policy allows AWS Context to assume the role only on behalf of the Agent Context account:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowAWSContextToAssumeRole", "Effect": "Allow", "Principal": { "Service": "context.amazonaws.com" }, "Action": [ "sts:AssumeRole", "sts:SetContext" ], "Condition": { "StringEquals": { "aws:SourceAccount": "444455556666" }, "ArnLike": { "aws:SourceArn": "arn:aws:context:us-east-1:444455556666:*" } } } ] } -
Attach the permissions policy for your source type to that identity: Permissions for metadata-only sources, Permissions for AWS Glue Data Catalog tables, Permissions for Amazon S3 Tables, Permissions for Amazon DynamoDB, or Permissions for databases that use Secrets Manager.
-
Create the ingestion role (
ContextIngestionRole), which all AWS Glue Data Catalog source types share. The following trust policy allows AWS Glue Data Catalog to assume the role only on behalf of the source account’s catalog. If you connect catalogs in more than one Region, add anaws:SourceArnvalue for each:{ "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/*" ] } } } ] }Attach the following permissions policy to the role:
{ "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": "444455556666" } } }, { "Sid": "SendGlueMetadata", "Effect": "Allow", "Action": "glue:SendMetadata", "Resource": "arn:aws:glue:us-east-1:111122223333:catalog" } ] }The
context:SourceArncondition limits ingestion to the source account’s catalog and its AWS Glue connections. Sources whose data source is an AWS Glue connection, such as Amazon Redshift, need theconnection/*value. Theaws:ResourceAccountcondition limits ingestion to Agent Contexts in the Agent Context account. -
Make sure that the principal that creates the connection can pass the ingestion role (
iam:PassRole). If you use a data access role, the principal must also be able to pass it. -
Create the connection the same way as for a source in the same account (see AWS Glue tables and S3 tables). Use the source account’s catalog ARN or AWS Glue connection ARN as the data source, and the roles from the previous steps.
In the console, enter the source account ID to browse its resources. This requires the optional discovery statement in the source account’s AWS Glue Data Catalog resource policy (see AWS Glue Data Catalog sources).
-
Bind the
ACTIVEconnection into your Agent Context throughconnectionMappings, as you would for a source in the same account.
Permissions for metadata-only sources
For sources that are metadata only (see When to use cross-account access), attach the following policy to the identity that reads the source:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "GlueCatalogRead", "Effect": "Allow", "Action": [ "glue:GetCatalog", "glue:GetDatabase", "glue:GetDatabases" ], "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/*" ] } ] }
Permissions for AWS Glue Data Catalog tables
Attach the following policy to the identity that reads the source. The example grants access to one database, databaseName:
{ "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/databaseName", "arn:aws:glue:us-east-1:111122223333:table/databaseName/*" ] }, { "Sid": "GlueCatalogRead", "Effect": "Allow", "Action": [ "glue:GetCatalog", "glue:GetDatabase" ], "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/databaseName" ] }, { "Sid": "ReadTableData", "Effect": "Allow", "Action": [ "s3:ListBucket", "s3:GetObject", "s3:GetBucketLocation" ], "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": "*" } ] }
You need the ReadTableData statement only for real-time retrieval.
Permissions for Amazon S3 Tables
Attach the following policy to the identity that reads the source. The example grants access to the table bucket amzn-s3-demo-table-bucket:
{ "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": "GlueCatalogRead", "Effect": "Allow", "Action": [ "glue:GetCatalog", "glue:GetDatabase" ], "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/s3tablescatalog/amzn-s3-demo-table-bucket/*" ] }, { "Sid": "ReadS3TableBucket", "Effect": "Allow", "Action": [ "s3tables:GetTableBucket", "s3tables:GetNamespace", "s3tables:ListNamespaces", "s3tables:ListTables", "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": "*" } ] }
The source account must also grant this role access in the table bucket policy and in AWS Lake Formation (see Additional grants for Amazon S3 Tables).
Permissions for Amazon DynamoDB
Attach the following policy to the identity that reads the source. The example grants access to one table, tableName, through the dynamodb-connection
AWS Glue connection in the source account:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "UseGlueManagedConnector", "Effect": "Allow", "Action": "glue:ManagedConnector", "Resource": "*" }, { "Sid": "ValidateGlueConnection", "Effect": "Allow", "Action": "glue:GetConnection", "Resource": [ "arn:aws:glue:us-east-1:111122223333:catalog", "arn:aws:glue:us-east-1:111122223333:connection/dynamodb-connection" ] }, { "Sid": "ReadDynamoDBTables", "Effect": "Allow", "Action": [ "dynamodb:DescribeTable", "dynamodb:Scan", "dynamodb:Query", "dynamodb:GetItem", "dynamodb:PartiQLSelect" ], "Resource": "arn:aws:dynamodb:us-east-1:111122223333:table/tableName" } ] }
The source account must also allow this access in the table’s resource policy (see Additional grants for Amazon DynamoDB).
Permissions for databases that use Secrets Manager
Attach the following policy to the identity that reads the source. The example grants access through the database-connection
AWS Glue connection in the source account. Replace the secret ARN with the full ARN of the secret that the connection uses, including its six-character suffix:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "UseGlueManagedConnector", "Effect": "Allow", "Action": "glue:ManagedConnector", "Resource": "*" }, { "Sid": "ValidateGlueConnection", "Effect": "Allow", "Action": "glue:GetConnection", "Resource": [ "arn:aws:glue:us-east-1:111122223333:catalog", "arn:aws:glue:us-east-1:111122223333:connection/database-connection" ] }, { "Sid": "ReadConnectionSecret", "Effect": "Allow", "Action": [ "secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret" ], "Resource": "arn:aws:secretsmanager:us-east-1:111122223333:secret:database-secret-AbCdEf" }, { "Sid": "DecryptConnectionSecret", "Effect": "Allow", "Action": "kms:Decrypt", "Resource": "arn:aws:kms:us-east-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "Condition": { "StringEquals": { "kms:ViaService": "secretsmanager.us-east-1.amazonaws.com" } } } ] }
The source account must also allow this access in the secret’s resource policy and the key policy (see Additional grants for databases that use Secrets Manager).
Amazon Bedrock Managed Knowledge Bases
In the following examples, ContextQueryRole is the identity that reads the source: the caller’s IAM role or the connection’s data access role (see Cross-account access). The examples use 111122223333 for the source account, 444455556666 for the Agent Context account, KB12345678 for the knowledge base ID, and us-east-1 for the Region. Replace these values with your own.
To set up the connection, complete the following steps:
-
Create the ingestion role. Its trust policy allows Amazon Bedrock Knowledge Bases to assume it, and only on behalf of the source account’s knowledge base:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "bedrock.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "aws:SourceAccount": "111122223333" }, "ArnLike": { "aws:SourceArn": "arn:aws:bedrock:us-east-1:111122223333:knowledge-base/KB12345678" } } } ] }Attach the following permissions policy to the role:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "IngestFromKnowledgeBase", "Effect": "Allow", "Action": "context:IngestAgentContext", "Resource": "*", "Condition": { "ArnLike": { "context:SourceArn": "arn:aws:bedrock:us-east-1:111122223333:knowledge-base/KB12345678" }, "StringEquals": { "aws:ResourceAccount": "444455556666" } } }, { "Sid": "SendKnowledgeBaseEntities", "Effect": "Allow", "Action": "bedrock:SendKnowledgeBaseEntities", "Resource": "arn:aws:bedrock:us-east-1:111122223333:knowledge-base/KB12345678" } ] }The
context:SourceArncondition limits ingestion to the source account’s knowledge base. Theaws:ResourceAccountcondition limits it to Agent Contexts in the Agent Context account. Ingestion also needs theContextIngestionstatement in the knowledge base policy. -
(Optional) Create the data access role with the same trust policy as for AWS Glue Data Catalog sources:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowAWSContextToAssumeRole", "Effect": "Allow", "Principal": { "Service": "context.amazonaws.com" }, "Action": [ "sts:AssumeRole", "sts:SetContext" ], "Condition": { "StringEquals": { "aws:SourceAccount": "444455556666" }, "ArnLike": { "aws:SourceArn": "arn:aws:context:us-east-1:444455556666:*" } } } ] }Attach the following permissions policy to that identity:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ReadKnowledgeBase", "Effect": "Allow", "Action": [ "bedrock:Retrieve", "bedrock:GetDocumentContent", "bedrock:GetKnowledgeBase" ], "Resource": "arn:aws:bedrock:us-east-1:111122223333:knowledge-base/KB12345678" } ] } -
Make sure that the principal that creates the connection can pass the ingestion role (
iam:PassRole). If you use a data access role, the principal must also be able to pass it. -
Create the connection as you would for a knowledge base in the same account (see Connect a managed knowledge base to AWS Context). Use the knowledge base ARN in the source account, and the roles from the previous steps.
-
Bind the
ACTIVEconnection into your Agent Context throughconnectionMappings.