AWS Builder Center
Give Claude Code on Amazon Bedrock live Web Search access

Give Claude Code on Amazon Bedrock live Web Search access

Setup websearch for Claude Code on Bedrock - no data egress outside your AWS environment.

If you're using Claude Code, you already know how far it can get on training data and local context alone. But some questions need the live web, for example: a changelog published this morning, a pricing page that changed last week, a GitHub issue opened an hour ago. For these, Claude Code needs a web search tool it can call.
This post walks through wiring Claude Code up to Amazon Bedrock AgentCore Gateway's built-in Web Search connector - a fully managed, MCP-compliant tool with no search API keys to provision and no outbound credentials to manage and with zero data egress to the internet. Access is governed entirely through your own identity provider and AWS IAM, so there's no third-party search key floating around in a config file somewhere.

Why a gateway instead of a raw API key?

You could hand Claude Code a search API key directly. But routing through an AgentCore Gateway gets you:
  • No outbound credentials to leak. The gateway authenticates to the Web Search connector using its own IAM role, you don't need to store client-side.
  • Centralized access control. Every call is authorized against your identity provider before it ever reaches the search tool.
  • A standard MCP interface. Claude Code (or any other MCP client) talks to the gateway the same way it'd talk to any other MCP server.

The setup, at a high level

1. Set up your identity provider. The gateway's inbound auth is  CUSTOM_JWT.  It validates any JWT issued by an OIDC-compliant identity provider. Amazon Cognito is one option, but not the only one. Microsoft Entra ID or any other JWT-based provider works the same way, as long as it can issue tokens via an authorization-code + PKCE flow for a public (no-secret) client. You'll need a user pool / app registration with an app client configured for Claude Code to authenticate through, and a scope the gateway will check on every request.
2. Create the AgentCore Gateway. Create the gateway with  --authorizer-type CUSTOM_JWT , pointing its  discoveryUrl  at your identity provider's OIDC configuration and listing the allowed client(s) and scope(s). (One provider-specific detail worth knowing up front: some providers put the client identity in a  client_id  claim, others in  aud  — check which your provider uses, since the gateway's  allowedClients  vs.  allowedAudience  fields aren't interchangeable.)  Instructions 
3. Attach the Web Search connector as a gateway target. This is a built-in connector ( connectorId: web-search ). Outbound auth uses the gateway's own IAM role ( GATEWAY_IAM_ROLE ), which needs  bedrock-agentcore:InvokeWebSearch  permission.  Instructions .
4. (Optional) Configure a domain filter. If you want to restrict which domains the tool can query, the target supports a denylist via  parameterValues.domainFilter.exclude .  Instructions 
5. Connect Claude Code as an MCP client.  claude mcp add  the gateway's MCP endpoint, with a fixed OAuth callback port (some identity providers, like Cognito, require an exact-match redirect URI since there is no port-agnostic loopback leniency, so pin the port).
6. Test it. Run  /mcp  in Claude Code to confirm the connector is live, then ask something time-sensitive and watch it search and cite sources.

What you end up with

Claude Code gets real, live web access, but every call passes through your gateway, is authorized against your identity provider, and reaches the search tool using credentials that never leave AWS. Swap identity providers later without touching how Claude Code connects; the MCP interface stays the same.



Setting up Amazon Cognito as the identity provider (CLI)

If you go with Cognito for step 1, here's the CLI path.
Create the user pool:
export REGION="us-east-1"

USER_POOL_ID=$(aws cognito-idp create-user-pool \
--region "$REGION" \
--pool-name "agentcore-gw-pool" \
--auto-verified-attributes email \
--username-attributes email \
--admin-create-user-config AllowAdminCreateUserOnly=true \
--query 'UserPool.Id' --output text)

echo "User Pool: $USER_POOL_ID"
Create the Hosted UI domain:
export DOMAIN_PREFIX="agentcore-gw" # must not contain "aws", "amazon", or "cognito"

aws cognito-idp create-user-pool-domain \
--region "$REGION" \
--domain "$DOMAIN_PREFIX" \
--user-pool-id "$USER_POOL_ID"
Create a resource server with the scope the gateway will validate:
aws cognito-idp create-resource-server \
--region "$REGION" \
--user-pool-id "$USER_POOL_ID" \
--identifier "gateway" \
--name "AgentCore Gateway resource server" \
--scopes ScopeName=access_as_user,ScopeDescription="Access the AgentCore Gateway as the signed-in user"
Create a public app client (no secret) for Claude Code, using PKCE:
export CALLBACK_PORT=8080

CLIENT_ID=$(aws cognito-idp create-user-pool-client \
--region "$REGION" \
--user-pool-id "$USER_POOL_ID" \
--client-name "claude-code-client" \
--no-generate-secret \
--allowed-o-auth-flows code \
--allowed-o-auth-flows-user-pool-client \
--allowed-o-auth-scopes "openid" "gateway/access_as_user" \
--supported-identity-providers "COGNITO" \
--callback-urls "http://localhost:${CALLBACK_PORT}/callback" \
--query 'UserPoolClient.ClientId' --output text)

echo "Client ID: $CLIENT_ID"
Create a test user (the pool is admin-provisioned only, so there's no self-service signup page):
TEST_EMAIL="claude-code-user@example.com"
TEST_PASSWORD="ChangeMe123"

aws cognito-idp admin-create-user \
--region "$REGION" \
--user-pool-id "$USER_POOL_ID" \
--username "$TEST_EMAIL" \
--user-attributes Name=email,Value="$TEST_EMAIL" Name=email_verified,Value=true \
--message-action SUPPRESS

aws cognito-idp admin-set-user-password \
--region "$REGION" \
--user-pool-id "$USER_POOL_ID" \
--username "$TEST_EMAIL" \
--password "$TEST_PASSWORD" \
--permanent
Grab the discovery URL you'll need for the gateway's  CUSTOM_JWT  authorizer:
DISCOVERY_URL="https://cognito-idp.${REGION}.amazonaws.com/${USER_POOL_ID}/.well-known/openid-configuration"
echo "Discovery URL: $DISCOVERY_URL"
With  $USER_POOL_ID ,  $CLIENT_ID , and  $DISCOVERY_URL  in hand, you're ready for step 2- creating the gateway with  allowedClients  set to  $CLIENT_ID  (Cognito access tokens carry a  client_id  claim, not  aud , so use  allowedClients  rather than  allowedAudience ).


Have questions about adapting this to a different identity provider, or hitting a snag with the gateway setup? Drop a comment below.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article