Amazon Bedrock AgentCore Gateway with Cedar policies and Amazon Cognito scopes

Amazon Cognito M2M client → MCP client → AgentCore Gateway Cedar policy → AWS Lambda Order tools

Per-tool authorization on an Amazon Bedrock AgentCore Gateway: Cedar policies allow each Amazon Cognito scope one AWS Lambda tool and deny the other.

This pattern deploys an Amazon Bedrock AgentCore Gateway with an AWS Lambda target that exposes two tools. A policy engine from Policy in Amazon Bedrock AgentCore is attached to the gateway in ENFORCE mode, and Cedar denies every tool call unless a policy permits it.
Amazon Cognito has one app client per scope (OAuth 2.0 client credentials). The gateway JWT authorizer accepts tokens from these clients, and each Cedar policy permits one tool when the scope claim of the access token contains the matching scope.
With the same gateway, one token is allowed lookup_order and denied cancel_order, and the other token is the reverse. The decision is taken inside the gateway, so the denied call does not invoke the function.

< 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-gateway-cedar/typescript/cdk

Deploy

npm installIf this account and Region have never been used with the AWS CDK, run npx cdk bootstrap once.npx cdk deploy


Testing

Get an access token for each Amazon Cognito app client, then call lookup_order and cancel_order through the gateway MCP endpoint with each token. Expected: each token is allowed one tool and denied the other.
See the GitHub repo for the exact commands, the check that denied calls do not invoke the function, and the expected output.

Cleanup

npx cdk destroy

Created by:

Nithin Chandran R

Nithin Chandran R

Technical Account Manager at AWS