Multi-tenant Amazon Bedrock AgentCore Runtime with Amazon Cognito

Client → Amazon Cognito User pool → Amazon Bedrock AgentCore Runtime → Amazon DynamoDB Tenant table → Amazon Bedrock

Authenticate an Amazon Bedrock AgentCore Runtime agent with Amazon Cognito and enforce per-tenant data isolation using Amazon Bedrock AgentCore Identity JWT authorization.

This pattern secures an Amazon Bedrock AgentCore Runtime agent with Amazon Cognito as the OAuth 2.0 / JWT identity provider.
Two Cognito groups represent two tenants. AgentCore Identity validates the inbound Cognito JWT with a custom JWT authorizer before the request reaches the agent.
The agent reads the caller's tenant from the validated cognito:groups claim and gives the model one Amazon DynamoDB tool bound to that tenant. The tool queries a single table partitioned by tenant_id.
Because the tenant comes from the token and not the prompt, the agent can only read the caller's own tenant data, even if a prompt asks for another tenant's.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/agentcore-identity-cognito-multi-tenant/python/cdk

Deploy

python3 -m venv .venvsource .venv/bin/activatepip3 install -r requirements.txtexport CDK_DEFAULT_REGION=us-west-2cdk deploy


Testing

Seed data: cd test && ./seed_tenant_data.sh <TenantTableName> us-west-2
Get a token for a tenant user: ./get_token.sh
Invoke the agent: export AGENT_ARN=<AgentRuntimeArn> && export BEARER_TOKEN=<token> && python test_multi_tenant.py "List my orders"
Repeat for a second tenant user and confirm each caller only sees its own tenant's data.

Cleanup

Delete the stack: cdk destroy

Created by:

Sudhansu Mohapatra

Sudhansu Mohapatra

Delivery Consultant at AWS