Put Claude Code on Amazon Bedrock behind your own sign-in with AgentCore Gateway
Part 1 of 5: Amazon Bedrock AgentCore Gateway can stand in front of Claude on Bedrock and your MCP servers, behind your own sign-in. This is the step-by-step guide we wished we'd had, with a check after every step.

Amazon Bedrock AgentCore Gateway lets you put Claude on Amazon Bedrock, and the MCP servers your people use, behind one address and your own sign-in. This guide builds that from nothing, checks every step, and ends with Claude Code making its model calls and tool calls through the gateway.
The short version
- One gateway gives Claude two doors:
/inferencefor model calls and/mcpfor tool calls. - Cognito, or your own identity provider, signs people in. The gateway checks their ID token on every call.
- An inference target calls Claude on Bedrock with the gateway’s own role, so laptops hold no AWS credentials.
- Claude Code needs a handful of environment variables and one MCP server to use it.
- Decide your sign-in type and tool search before creating the gateway: neither can change later.
Our example organisation is Metomic Boundary, an invented payments company with 900 staff. It wants Claude Code on Bedrock in its own AWS account. Every name below is theirs; swap in yours.
The AgentCore Gateway series, in order:
- Put Claude Code on Bedrock behind your own sign-in (this guide)
- Run Claude Desktop through the same gateway
- Add GitHub’s MCP server with a read-only token
- Give each person their own HubSpot sign-in
- Count what the MCP tool definitions cost per model call
What does the finished setup look like?
Claude Code ──► AgentCore Gateway ──/inference──► Amazon Bedrock (Claude)
(ID token) │
└──/mcp──► an MCP server (DeepWiki, public, for testing)
Cognito user pool ──► issues the ID token the gateway checks
The gateway is a Model Context Protocol (MCP) endpoint with targets behind it. If MCP gateways are new to you, start with what an MCP gateway is.
What do you need before you start?
- An AWS account and a region with AgentCore. We used London,
eu-west-2. - The AWS CLI, and Python with boto3 1.44 or later. Our CLI (2.34) didn’t know about inference targets, so that one step uses boto3.
- Bedrock access to at least one active Claude model.
- Claude Code installed.
- Permissions on your own AWS identity to do all of this. You run every command below as yourself, so your own credentials, not the gateway’s role from Step 3, have to be allowed to list and invoke Bedrock models, create and read a Cognito user pool and its users, create an IAM role and pass it to AgentCore, and create the gateway and its targets. An account admin already can; on a scoped role,
aws bedrock list-inference-profilesin Step 1 is the first thing that stops.
If you have to build that scoped role, this is its shape. We ran the guide from an account that could already do everything, so treat it as the actions each step touches rather than a least-privilege policy we have tested on its own, and tighten the resources to your account and names:
{
"Version": "2012-10-17",
"Statement": [
{ "Sid": "ListAndCallModels", "Effect": "Allow",
"Action": ["bedrock:ListInferenceProfiles", "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream"],
"Resource": "*" },
{ "Sid": "SignIn", "Effect": "Allow",
"Action": ["cognito-idp:CreateUserPool", "cognito-idp:CreateUserPoolClient", "cognito-idp:CreateUserPoolDomain",
"cognito-idp:UpdateUserPoolClient", "cognito-idp:DescribeUserPool", "cognito-idp:AdminCreateUser",
"cognito-idp:AdminSetUserPassword", "cognito-idp:InitiateAuth",
"cognito-idp:DeleteUserPool", "cognito-idp:DeleteUserPoolDomain"],
"Resource": "*" },
{ "Sid": "TheGatewayRole", "Effect": "Allow",
"Action": ["iam:CreateRole", "iam:PutRolePolicy", "iam:GetRole", "iam:PassRole",
"iam:DeleteRolePolicy", "iam:DeleteRole"],
"Resource": "arn:aws:iam::123456789012:role/boundary-claude" },
{ "Sid": "TheGateway", "Effect": "Allow",
"Action": ["bedrock-agentcore:CreateGateway", "bedrock-agentcore:GetGateway",
"bedrock-agentcore:CreateGatewayTarget", "bedrock-agentcore:GetGatewayTarget",
"bedrock-agentcore:ListGatewayTargets", "bedrock-agentcore:DeleteGatewayTarget",
"bedrock-agentcore:DeleteGateway"],
"Resource": "*" }
]
}
Include iam:PassRole: creating the gateway hands it the Step 3 role, and AWS checks you may pass a role to a service before it lets you.
Set a few shell variables once. Every command below uses them.
export AWS_REGION=eu-west-2
export ACCOUNT=123456789012 # your account
export NAME=boundary-claude # gateway, pool and role name
Step 1: Which Claude models can your account call on Bedrock?
List the inference profiles, then make sure one actually answers.
aws bedrock list-inference-profiles \
--query "inferenceProfileSummaries[?contains(inferenceProfileId,'anthropic')].[inferenceProfileId,status]" --output text
aws bedrock-runtime invoke-model --model-id eu.anthropic.claude-haiku-5-5 \
--body '{"anthropic_version":"bedrock-2023-05-31","max_tokens":50,"messages":[{"role":"user","content":"Say hello in five words."}]}' \
--cli-binary-format raw-in-base64-out /dev/stdout
Check: you get JSON with Claude’s answer. If the error says the model “is Legacy and you have not been actively using the model in the last 30 days”, pick another. We use eu.anthropic.claude-sonnet-5-5 and eu.anthropic.claude-haiku-5-5.
Two things here are compliance questions, not just capability ones. The first is where the call runs: eu.anthropic.* is a cross-region inference profile, so Bedrock may serve the request from any region in that geography. If every request has to stay in one country, check the profile’s member regions before you rely on it, which is also why the role policy in Step 3 wildcards the region rather than pinning it. The second is what Bedrock keeps, and the honest answer is that it depends on the model. Bedrock exposes a data-retention mode at the account and project level. Set it to none and nothing you send or receive is written to durable storage. But some models require AWS to retain your inputs and outputs for up to 30 days of human review as a condition of access, so they cannot run under zero retention; others can. That review stays inside the AWS boundary, and the provider does not receive your content in any current mode, so the risk here is not a model vendor training on your prompts. It is that the retention and review terms are set per model by each provider, not once for all of Bedrock, so a regulated team checks them model by model and pins them with the retention mode, with a service control policy denying anything but none if they want a hard floor. None of that reads the traffic: Bedrock still sends whatever your agent hands it, so inspecting and redacting what each call carries is a separate job. People assume you cannot run DLP on Bedrock; you can, just not with Bedrock’s own retention terms alone. On the agent’s traffic, a governed gateway is the Bedrock-native place to do it, and Anthropic’s Inference Hooks are the equivalent on Claude Enterprise.
Step 2: How do you give the gateway its own sign-in?
The gateway needs an OpenID Connect issuer whose tokens it can check. A Cognito user pool is the quickest; later you can federate it to Okta or Microsoft Entra ID.
POOL_ID=$(aws cognito-idp create-user-pool --pool-name $NAME --username-attributes email \
--admin-create-user-config AllowAdminCreateUserOnly=true --query UserPool.Id --output text)
CLIENT_ID=$(aws cognito-idp create-user-pool-client --user-pool-id $POOL_ID --client-name $NAME \
--no-generate-secret --explicit-auth-flows ALLOW_USER_PASSWORD_AUTH ALLOW_REFRESH_TOKEN_AUTH \
--query UserPoolClient.ClientId --output text)
# A hosted sign-in page and the code grant, which Claude Desktop needs later.
aws cognito-idp create-user-pool-domain --user-pool-id $POOL_ID --domain $NAME-$ACCOUNT --managed-login-version 1
aws cognito-idp update-user-pool-client --user-pool-id $POOL_ID --client-id $CLIENT_ID --client-name $NAME \
--explicit-auth-flows ALLOW_USER_PASSWORD_AUTH ALLOW_REFRESH_TOKEN_AUTH --supported-identity-providers COGNITO \
--allowed-o-auth-flows code --allowed-o-auth-scopes openid email profile --allowed-o-auth-flows-user-pool-client \
--callback-urls "http://127.0.0.1:53180/callback"
export POOL_ID CLIENT_ID; echo $POOL_ID $CLIENT_ID
The client has no secret because desktop apps can’t keep one. Note the scopes: there’s no offline_access, because Cognito refuses it.
Check: aws cognito-idp describe-user-pool --user-pool-id $POOL_ID --query UserPool.Domain prints your domain.
Step 3: What may the gateway’s role do?
The gateway calls Bedrock with its own IAM role. It needs to invoke Claude and to read Bedrock’s model list.
aws iam create-role --role-name $NAME --assume-role-policy-document "{
\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",
\"Principal\":{\"Service\":\"bedrock-agentcore.amazonaws.com\"},\"Action\":\"sts:AssumeRole\",
\"Condition\":{\"StringEquals\":{\"aws:SourceAccount\":\"$ACCOUNT\"}}}]}"
aws iam put-role-policy --role-name $NAME --policy-name invoke-claude --policy-document "{
\"Version\":\"2012-10-17\",\"Statement\":[
{\"Effect\":\"Allow\",\"Action\":[\"bedrock:InvokeModel\",\"bedrock:InvokeModelWithResponseStream\"],
\"Resource\":[\"arn:aws:bedrock:$AWS_REGION:$ACCOUNT:inference-profile/eu.anthropic.*\",
\"arn:aws:bedrock:*::foundation-model/anthropic.*\"]},
{\"Effect\":\"Allow\",\"Action\":[\"bedrock:List*\",\"bedrock:Get*\"],\"Resource\":\"*\"}]}"
sleep 10 # a new role takes a few seconds before AgentCore can use it
The List* and Get* statement is the one people miss. Without it, the inference target fails at creation.
Step 4: How do you create the gateway?
Two choices are permanent: the sign-in type and semantic tool search. We use a custom JSON Web Token (JWT) authorizer pointed at the pool, with the app client as the allowed audience.
# create_gateway.py
import boto3, os
env = os.environ
c = boto3.client("bedrock-agentcore-control", region_name=env["AWS_REGION"])
g = c.create_gateway(
name=env["NAME"], protocolType="MCP", roleArn=f"arn:aws:iam::{env['ACCOUNT']}:role/{env['NAME']}",
authorizerType="CUSTOM_JWT",
authorizerConfiguration={"customJWTAuthorizer": {
"discoveryUrl": f"https://cognito-idp.{env['AWS_REGION']}.amazonaws.com/{env['POOL_ID']}/.well-known/openid-configuration",
"allowedAudience": [env["CLIENT_ID"]]}},
protocolConfiguration={"mcp": {"supportedVersions": ["2025-03-26", "2025-06-18", "2025-11-25"]}})
print(g["gatewayId"], g["gatewayUrl"])
python3 create_gateway.py
export GATEWAY_ID=<the id it printed>
export GW=$(aws bedrock-agentcore-control get-gateway --gateway-identifier $GATEWAY_ID --query gatewayUrl --output text | sed 's#/mcp$##')
We list three MCP protocol versions. Claude Desktop asks for 2025-03-26, and each person’s own SaaS sign-in needs 2025-11-25. We added them to ours afterwards with update_gateway. That call replaces the whole configuration, so pass every field again or lose it. Add "searchType": "SEMANTIC" to the mcp block now if you want AgentCore’s semantic tool search.
Check: aws bedrock-agentcore-control get-gateway --gateway-identifier $GATEWAY_ID --query status reads READY. If it failed with a role error, wait ten seconds and run it again.
Step 5: How do you add Claude as an inference target?
Why send model calls through the gateway at all, instead of letting Claude Code reach Bedrock directly? Two reasons, and they are the point of the whole exercise. Observability: every model call passes one point you own, which is where an audit trail of who asked the model what belongs, next to the tool calls from the same session. The gateway’s own logging is off until you switch it on, so switch it on first. Control: the inference target is a seam. This guide stops at creating it, but add a gateway interceptor and, because it runs in buffered mode, the point that already reads a tool call reads the whole prompt and the whole answer too, streamed or not. That is where redaction and DLP on the model path live, and the job Inference Hooks do on Claude Enterprise. Send Claude Code straight to Bedrock and there is no seam at all.
# add_claude.py
import boto3, os
c = boto3.client("bedrock-agentcore-control", region_name=os.environ["AWS_REGION"])
t = c.create_gateway_target(gatewayIdentifier=os.environ["GATEWAY_ID"], name="claude",
targetConfiguration={"inference": {"connector": {"source": {"connectorId": "bedrock-runtime"}}}},
credentialProviderConfigurations=[{"credentialProviderType": "GATEWAY_IAM_ROLE"}])
print(t["targetId"])
Check: aws bedrock-agentcore-control list-gateway-targets --gateway-identifier $GATEWAY_ID --query "items[].[name,status]" --output text shows claude READY. FAILED almost always means the role lacks bedrock:List*. Read the reason with get-gateway-target … --query statusReasons, fix the role, delete the target and create it again.
Step 6: How do you add an MCP server to test with?
DeepWiki’s MCP server is public and needs no credentials, which makes it a good first target.
aws bedrock-agentcore-control create-gateway-target --gateway-identifier $GATEWAY_ID --name deepwiki \
--target-configuration '{"mcp":{"mcpServer":{"endpoint":"https://mcp.deepwiki.com/mcp"}}}'
Check: the target reaches READY. The gateway now lists its tools as deepwiki___<tool>, with three underscores.
Step 7: How does someone sign in and get a token?
Make yourself a user to test with. Later you’d federate the pool to your identity provider instead. Cognito’s default password rules want 8 or more characters, with upper and lower case, a number and a symbol. Signing in needs no AWS credentials, hence --no-sign-request. The password is typed, never stored, and the tokens go to files only you can read.
printf 'Email: '; read -r EMAIL
printf 'Password: '; read -rs PASSWORD; echo
# Once per person, with an admin's AWS credentials
aws cognito-idp admin-create-user --user-pool-id $POOL_ID --username "$EMAIL" --message-action SUPPRESS \
--user-attributes Name=email,Value="$EMAIL" Name=email_verified,Value=true
aws cognito-idp admin-set-user-password --user-pool-id $POOL_ID --username "$EMAIL" --password "$PASSWORD" --permanent
# The person, each time they need a token
umask 077
aws cognito-idp initiate-auth --no-sign-request --client-id $CLIENT_ID --auth-flow USER_PASSWORD_AUTH \
--auth-parameters "USERNAME=$EMAIL,PASSWORD=$PASSWORD" \
--query 'AuthenticationResult.[IdToken,RefreshToken]' --output text | {
read -r id refresh; printf '%s\n' "$id" > ~/.agentcore-id-token; printf '%s\n' "$refresh" > ~/.agentcore-refresh; }
This works in both zsh and bash. Use the ID token: its audience is the app client, which the gateway checks. The access token has no audience and no email, and the gateway refuses it.
Step 8: How do you confirm both doors work before involving Claude?
List the tools through /mcp:
curl -s "$GW/mcp" -H "Authorization: Bearer $(cat ~/.agentcore-id-token)" \
-H 'content-type: application/json' -H 'accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
Check: you see deepwiki___ask_wiki_question and two more. Lists come in pages of 30, so follow nextCursor once you add bigger servers. A bad or expired token gets a 401.
Call Claude through /inference:
curl -s "$GW/inference/model/eu.anthropic.claude-haiku-5-5/invoke" \
-H "Authorization: Bearer $(cat ~/.agentcore-id-token)" \
-H 'content-type: application/json' -H 'accept: application/json' \
-d '{"anthropic_version":"bedrock-2023-05-31","max_tokens":50,"messages":[{"role":"user","content":"Say hello in five words."}]}'
Check: Claude’s answer comes back as Bedrock’s usual JSON, with "stop_reason":"end_turn". Bedrock wants exactly one Accept type: application/json here, and application/vnd.amazon.eventstream for the streamed invoke-with-response-stream.
Step 9: How do you point Claude Code at the gateway?
export CLAUDE_CODE_USE_BEDROCK=1
export ANTHROPIC_BEDROCK_BASE_URL="$GW/inference"
export CLAUDE_CODE_SKIP_BEDROCK_AUTH=1
export ANTHROPIC_CUSTOM_HEADERS="Authorization: Bearer $(cat ~/.agentcore-id-token)"
export ANTHROPIC_MODEL=eu.anthropic.claude-sonnet-5-5
export ANTHROPIC_DEFAULT_HAIKU_MODEL=eu.anthropic.claude-haiku-5-5
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 # optional: nothing goes anywhere but the gateway
claude mcp add --transport http agentcore "$GW/mcp" --header "Authorization: Bearer $(cat ~/.agentcore-id-token)"
claude mcp list
Check, in order:
claude mcp listshowsagentcore: … (HTTP) - ✔ Connected.claude -p "Say hello"answers, so the model calls go through the gateway.- In a session, “Ask DeepWiki what octocat/Hello-World is for” calls
mcp__agentcore__deepwiki___ask_wiki_questionand answers.
When the hour is up. The ID token lasts an hour. Claude Code reads ANTHROPIC_CUSTOM_HEADERS when it starts, so renew the token and start it again:
aws cognito-idp initiate-auth --no-sign-request --client-id $CLIENT_ID --auth-flow REFRESH_TOKEN_AUTH \
--auth-parameters REFRESH_TOKEN="$(cat ~/.agentcore-refresh)" --query AuthenticationResult.IdToken --output text \
> ~/.agentcore-id-token
For the MCP server you can avoid the restart with a headersHelper: a script whose output is {"Authorization": "Bearer <token>"}. Claude Code runs it only in a folder you’ve trusted. Until you accept the trust prompt there, Claude Code tries OAuth instead and fails with “Incompatible auth server: does not support dynamic client registration”.
What goes wrong, and what does it mean?
| You see | Cause |
|---|---|
| 401 from the gateway | An access token, an expired ID token, or a token from another client |
| “is Legacy and you have not been actively using the model” | Pick an active model |
Inference target FAILED |
The role lacks bedrock:List* and bedrock:Get* |
The CLI rejects inference in a target |
An older CLI: use boto3 1.44 or later |
Settings vanish after update-gateway |
It replaces the whole configuration: pass every field again |
| “Incompatible auth server: does not support dynamic client registration” | Claude Code had no header for the server, so it tried OAuth against Cognito |
How do you take it all down?
Order matters. Targets go before the gateway, and a pool with a domain can’t be deleted until the domain is.
for t in $(aws bedrock-agentcore-control list-gateway-targets --gateway-identifier $GATEWAY_ID --query "items[].targetId" --output text); do
aws bedrock-agentcore-control delete-gateway-target --gateway-identifier $GATEWAY_ID --target-id $t
done
sleep 30 # targets take a moment to go
aws bedrock-agentcore-control delete-gateway --gateway-identifier $GATEWAY_ID
aws cognito-idp delete-user-pool-domain --user-pool-id $POOL_ID --domain $NAME-$ACCOUNT
aws cognito-idp delete-user-pool --user-pool-id $POOL_ID
aws iam delete-role-policy --role-name $NAME --policy-name invoke-claude
aws iam delete-role --role-name $NAME
rm -f ~/.agentcore-id-token ~/.agentcore-refresh
claude mcp remove agentcore
What’s still hard?
- It only covers what you point at it. claude.ai in a browser does not send its model calls through the AgentCore gateway you just built. The browser is still coverable, it just takes a different combination. Its MCP calls can run through a governed MCP gateway, so the tool traffic is inspected and redacted wherever the client lives, the browser included. The model calls are the part a gateway cannot see: Anthropic’s Inference Hooks cover those on Claude Enterprise, and a browser-level data firewall catches what people type and paste in. The trade-offs between a gateway and hooks are worth reading before you choose.
- MCP clients and OAuth. Cognito has no dynamic client registration, so clients that expect it can’t sign in through the gateway’s own discovery. Headers work everywhere we tried.
- Tool definitions add up. Every tool’s definition goes with every model call. With 90 tools behind our gateway, that was 104,388 tokens a call. We wrote up where that comes from and what to do about it.
- Tokens expire hourly. Model calls take the token at start-up, so long sessions need a restart or a wrapper that renews it.
What do you have now?
- One gateway in front of Claude on Bedrock and an MCP server, behind your sign-in.
- Claude Code using it for both, with no AWS credentials on the laptop.
- A check for each step to come back to when something breaks.
Next: Claude Desktop through the same gateway, then GitHub’s MCP server and each person’s own HubSpot sign-in. Standing the gateway up is the easy half. Deciding what each call may carry, from whom, with the whole chat in view, is the hard half, and what our governed MCP gateway is for. We’re working with a small number of security teams on governing agents like these. If you’ve done this differently, tell us.
Frequently asked questions
- Can Claude Code use Amazon Bedrock AgentCore Gateway instead of Bedrock directly?
- Yes. Set
CLAUDE_CODE_USE_BEDROCK=1, pointANTHROPIC_BEDROCK_BASE_URLat the gateway's/inferencepath, skip Bedrock's own signing withCLAUDE_CODE_SKIP_BEDROCK_AUTH=1, and send the person's ID token inANTHROPIC_CUSTOM_HEADERS. Claude Code then makes its model calls through the gateway, which calls Bedrock with its own role. In our test environment it used only the streamedInvokeModelcall. - Why does the gateway reject my Cognito access token?
- A gateway with a custom JWT authorizer checks the token's audience against the app client you allowed. Cognito's ID tokens carry that audience; its access tokens don't, and they carry no email either. Send the ID token. It lasts an hour, so renew it with the refresh token rather than asking the person to sign in again.
- Can I change a gateway's sign-in type or turn on semantic search later?
- No to both. A gateway's authorizer type is fixed when you create it, so moving from IAM sign-in to an identity provider means making the gateway again, targets and all. AWS's guide also says semantic tool search can only be enabled when a gateway is created. Decide both before you run
create-gateway. - Why did my inference target go to FAILED?
- When you create an inference target, the gateway discovers the provider's models, so its role needs Bedrock's read-only List and Get actions as well as
InvokeModel. Ours failed onbedrock:ListProvisionedModelThroughputs. Addbedrock:List*andbedrock:Get*to the gateway's role, delete the failed target and create it again. The status reason names the missing action. - Which Claude models can I use through the gateway?
- Any model your account can invoke through a Bedrock inference profile, as long as the gateway's role may invoke it. Check the model is active first. Bedrock marks a model Legacy when your account hasn't used it for 30 days, and then the first message fails with an access denied error that the gateway passes straight through to Claude.