Organizations need seamless access to their structured data repositories to power intelligent AI agents. However, when these resources span multiple AWS accounts integration challenges can arise. This post explores a practical solution for connecting Amazon Bedrock agents to knowledge bases in Amazon Redshift clusters residing in different AWS accounts.
Organizations that build AI agents using Amazon Bedrock can maintain their structured data in Amazon Redshift clusters. When these data repositories exist in separate AWS accounts from their AI agents, they face a significant limitation: Amazon Bedrock Knowledge Bases doesn’t natively support cross-account Redshift integration.
This creates a challenge for enterprises with multi-account architectures who want to:
Our solution enables cross-account knowledge base integration through a secure, serverless architecture that maintains secure access controls while allowing AI agents to query structured data. The approach uses AWS Lambda as an intermediary to facilitate secure cross-account data access.

The action flow as shown above:
The solution follows these key components:
This solution requires you to have the following:
jq is lightweight command-line JSON processor. For example, in Mac you can use the command brew install jq (jq-1.7.1-apple – current version) to install it.Let’s call the AWS account profile, agent profile that has the Amazon Bedrock agent. Similarly, the AWS account profile be called agent-kb that has the Amazon Bedrock knowledge base with Amazon Redshift Serverless and the structured data source. We will use the us-west-2 US West (Oregon) AWS Region but feel free to choose another AWS Region as necessary (the prerequisites will be applicable to the AWS Region you choose to deploy this solution in). We will use the meta.llama3-1-70b-instruct-v1:0 model for the agent-kb. This is an available on-demand model in us-west-2. You are free to choose other models with cross-Region inference but that would mean changing the roles and polices accordingly and enable model access in all Regions they are available in. Based on our model choice for this solution the AWS Region must be us-west-2. For the agent we will be using an Amazon Bedrock agent optimized model like us.amazon.nova-pro-v1:0.
The following is a step-by-step implementation guide. Make sure to perform all steps in the same AWS Region in both accounts.
These steps are to deploy and test an end-to-end solution from scratch and if you are already running some of these components, you may skip over those steps.
| Profile | AWS account | Description |
| agent | 111122223333 | Account for the Bedrock Agent |
| agent-kb | 999999999999 | Account for the Bedrock Knowledge base |
Note: These steps use example profile names and account numbers, please replace with actuals before running.
| Input parameter | Value | Description |
| –agent-kb-profile | agent-kb | The agent knowledgebase profile that you set up with the AWS CLI with aws_access_key_id, aws_secret_access_key as mentioned in the prerequisites. |
| –lambda-role | lambda_bedrock_kb_query_role | This is the IAM role the agent account Bedrock agent action group lambda will assume to connect to the Redshift cross account |
| –kb-access-role | bedrock_kb_access_role | This is the IAM role the agent-kb account which the lambda_bedrock_kb_query_role in agent account assumes to connect to the Redshift cross account |
| –kb-access-policy | bedrock_kb_access_policy | IAM policy attached to the IAM role bedrock_kb_access_role |
| –lambda-policy | lambda_bedrock_kb_query_policy | IAM policy attached to the IAM role lambda_bedrock_kb_query_role |
| –knowledge-base-id | XXXXXXXXXX | Replace with the actual knowledge base ID created in Step 4 |
| –agent-account | 111122223333 | Replace with the 12-digit AWS account number where the Bedrock agent is running. (agent account) |
| –agent-kb-account | 999999999999 | Replace with the 12-digit AWS account number where the Bedrock knowledge base is running. (agent-kb acccount) |
cd /my/location
chmod +x create_bedrock_agent_kb_roles_policies.sh
./create_bedrock_agent_kb_roles_policies.sh –help
./create_bedrock_agent_kb_roles_policies.sh --agent-profile agent
--agent-kb-profile agent-kb
--lambda-role lambda_bedrock_kb_query_role
--kb-access-role bedrock_kb_access_role
--kb-access-policy bedrock_kb_access_policy
--lambda-policy lambda_bedrock_kb_query_policy
--knowledge-base-id XXXXXXXXXX
--agent-account 111122223333
--agent-kb-account 999999999999


lambda_bedrock_kb_query_role as that will be the value of CloudFormation stack parameter AgentLambdaExecutionRoleArn in the next step.
bedrock_kb_access_role as that will be the value of CloudFormation stack parameter TargetRoleArn in the next step.


| Parameter | Value | Description |
| Stack name | bedrock-agent-connect-kb-cross-account-agent | You can choose any name |
| AgentFoundationModelId | us.amazon.nova-pro-v1:0 | Do not change |
| AgentLambdaExecutionRoleArn | arn:aws:iam:: 111122223333:role/lambda_bedrock_kb_query_role | Replace with you agent account number |
| BedrockAgentDescription | Agent to query inventory data from Redshift Serverless database | Keep this as default |
| BedrockAgentInstructions | You are an assistant that helps users query inventory data from our Redshift Serverless database using the action group. | Do not change |
| BedrockAgentName | bedrock_kb_query_cross_account | Keep this as default |
| KBFoundationModelId | meta.llama3-1-70b-instruct-v1:0 | Do not change |
| KnowledgeBaseId | XXXXXXXXXX | Knowledge base id from Step 4 |
| TargetRoleArn | arn:aws:iam::999999999999:role/bedrock_kb_access_role | Replace with you agent-kb account number |









Some recommended best practices:
It is recommended that you clean up any resources you do not need anymore to avoid any unnecessary charges:

delete-bedrock-agent-kb-roles-policies.sh from the aws-samples GitHub repository.
cd /my/location
chmod +x delete-bedrock-agent-kb-roles-policies.sh
./ delete-bedrock-agent-kb-roles-policies.sh –help
delete-bedrock-agent-kb-roles-policies.sh with the same values for the same input parameters as in Step7 when running the create_bedrock_agent_kb_roles_policies.sh script. Note: Enter the correct account numbers for agent-account and agent-kb-account before running.
./delete-bedrock-agent-kb-roles-policies.sh --agent-profile agent
--agent-kb-profile agent-kb
--lambda-role lambda_bedrock_kb_query_role
--kb-access-role bedrock_kb_access_role
--kb-access-policy bedrock_kb_access_policy
--lambda-policy lambda_bedrock_kb_query_policy
--agent-account 111122223333
--agent-kb-account 999999999999
The script will ask for a confirmation, say yes and press enter.

This solution demonstrates how the Amazon Bedrock agent in the agent account can query the Amazon Bedrock knowledge base in the agent-kb account.
This solution uses Amazon Bedrock Knowledge Bases for structured data to create a more integrated approach to cross-account data access. The knowledge base in agent-kb account connects directly to Amazon Redshift Serverless in a private VPC. The Amazon Bedrock agent in the agent account invokes an AWS Lambda function as part of its action group to make a cross-account connection to retrieve response from the structured knowledge base.
This architecture offers several advantages:
As Amazon Bedrock continues to evolve, you can take advantage of future enhancements to knowledge base functionality while maintaining your multi-account architecture.
Kunal Ghosh is an expert in AWS technologies. He passionate about building efficient and effective solutions on AWS, especially involving generative AI, analytics, data science, and machine learning. Besides family time, he likes reading, swimming, biking, and watching movies, and he is a foodie.
Arghya Banerjee is a Sr. Solutions Architect at AWS in the San Francisco Bay Area, focused on helping customers adopt and use the AWS Cloud. He is focused on big data, data lakes, streaming and batch analytics services, and generative AI technologies.
Indranil Banerjee is a Sr. Solutions Architect at AWS in the San Francisco Bay Area, focused on helping customers in the hi-tech and semi-conductor sectors solve complex business problems using the AWS Cloud. His special interests are in the areas of legacy modernization and migration, building analytics platforms and helping customers adopt cutting edge technologies such as generative AI.
Vinayak Datar is Sr. Solutions Manager based in Bay Area, helping enterprise customers accelerate their AWS Cloud journey. He’s focusing on helping customers to convert ideas from concepts to working prototypes to production using AWS generative AI services.
Manuel Rioux est fièrement propulsé par WordPress