Claude Code を Amazon Bedrock API Keys 経由で実行してみた
こんにちは!クラウド事業本部コンサルティング部のたかくに(@takakuni_)です。
Claude Code v1.0.51 で AWS_BEARER_TOKEN_BEDROCK 環境変数を利用した Bedrock API keys による認証がサポートされました。
Added support for Bedrock API keys through environment variable AWS_BEARER_TOKEN_BEDROCK
先日、出たばっかりですが、サポートの速さに圧巻ですね。
今回は Bedrock API keys を利用して Claude Code を試してみたいと思います。
やってみた
今回のアップデートに際し、ドキュメントも更新されています。オプション D として、Bedrock API keys 経由の利用方法が記載されています。
今回は Short-term な API キーを発行して、利用してみます。マネジメントコンソールから Generate short-term API Keys
をクリックします。
出力された API キーをメモしておきましょう。
環境変数を設定します。AWS_BEARER_TOKEN_BEDROCK
以外は概ね一緒ですね。
API Key の性質上、AWS_REGION
の部分は発行したリージョンに合わせましょう。
# Amazon Bedrock を使用する
export CLAUDE_CODE_USE_BEDROCK=1
# API Key と同じリージョンを選択する
export AWS_REGION="ap-northeast-1"
# API Key を設定する
export AWS_BEARER_TOKEN_BEDROCK=your-bedrock-api-key
Claude Code を起動します。/status
で API Configuration が AWS Bedrock へ向いていることがわかります。
また、/model
では、Opus が指定されています。(現状、Opus は US の推論プロファイルでサポートしているため、us.anthropic.claude-opus-4-20250514-v1:0
となっていました)
takakuni@ bedrock-api-key % claude
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Do you trust the files in this folder? │
│ │
│ /Users/takakuni/Desktop/bedrock-api-key │
│ │
│ Claude Code may read files in this folder. Reading untrusted files may lead Claude Code to behave in unexpected ways. │
│ │
│ With your permission Claude Code may execute files in this folder. Executing untrusted code is unsafe. │
│ │
│ https://docs.anthropic.com/s/claude-code-security │
│ │
│ ❯ 1. Yes, proceed │
│ 2. No, exit │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Enter to confirm · Esc to exit
╭────────────────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: /Users/takakuni/Desktop/bedrock-api-key │
╰────────────────────────────────────────────────────────────╯
Tips for getting started:
1. Run /init to create a CLAUDE.md file with instructions for Claude
2. Use Claude to help with file analysis, editing, bash commands and git
3. Be as specific as you would with another engineer for the best results
4. ✔ Run /terminal-setup to set up terminal integration
Claude Code Status v1.0.51
L Session ID: a318733b-398d-48dc-afad-a4d1c647694a
Working Directory
L /Users/takakuni/Desktop/bedrock-api-key
IDE Integration • /config
✔ Connected to Cursor extension
L Installed Cursor extension version 1.0.51 (server version: 1.0.45)
MCP servers • /mcp
✔ aws-documentation-mcp-server
✔ playwright
API Configuration
L API Provider: AWS Bedrock
L AWS Region: ap-northeast-1
Model • /model
L opus (us.anthropic.claude-opus-4-20250514-v1:0)
Press Enter to continue…
もちろん、hello
とプロンプトを投げても、 400 エラーが返ってきます。
> hello
⎿ API Error (us.anthropic.claude-opus-4-20250514-v1:0): 400 The provided model identifier is invalid.
モデルを Sonnet に切り替えました。リージョンから自動的に APAC の推論プロファイルに切り替えられていますね。こちらはうまく応答が返ってきています。
> /model
⎿ Set model to sonnet (apac.anthropic.claude-sonnet-4-20250514-v1:0)
> hello
⏺ Hello! I'm Claude Code, ready to help you with your software engineering tasks. What would you like to work on today?
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ > │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
? for shortcuts ◯
続いてアプリケーション推論プロファイルを指定してみます。AWS CLI から Sonnet 4 をベースに作成します。
aws bedrock create-inference-profile --region 'ap-northeast-1' \
--inference-profile-name 'claude-code-bedrock-profile' \
--description 'takakuni-bedrock-profile' \
--model-source '{"copyFrom": "arn:aws:bedrock:ap-northeast-1:123456789012:inference-profile/apac.anthropic.claude-sonnet-4-20250514-v1:0"}' \
--tags '[{"key": "CostAllocateTag","value": "takakuni"}]'
~ $ aws bedrock create-inference-profile --region 'ap-northeast-1' \
> --inference-profile-name 'claude-code-bedrock-profile' \
> --description 'takakuni-bedrock-profile' \
> --model-source '{"copyFrom": "arn:aws:bedrock:ap-northeast-1:123456789012:inference-profile/apac.anthropic.claude-sonnet-4-20250514-v1:0"}' \
> --tags '[{"key": "CostAllocateTag","value": "takakuni"}]'
{
"inferenceProfileArn": "arn:aws:bedrock:ap-northeast-1:123456789012:application-inference-profile/hdxk4zqkrcgh",
"status": "ACTIVE"
}
~
作成されたアプリケーション推論プロファイルの ARN を /model
で指定します。
正しくセットされ、うまく応答されていますね。
> /model arn:aws:bedrock:ap-northeast-1:123456789012:application-inference-profile/hdxk4zqkrcgh
⎿ Set model to arn:aws:bedrock:ap-northeast-1:123456789012:application-inference-profile/hdxk4zqkrcgh
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Select Model │
│ Switch between Claude models. Applies to this session and future Claude Code sessions. For custom model names, specify with --model. │
│ │
│ 1. Default (recommended) Use the default model (currently Sonnet 3.7) · $3/$15 per Mtok │
│ 2. Sonnet Sonnet 4 for daily use · $3/$15 per Mtok │
│ 3. Opus Opus 4 for complex tasks · $15/$75 per Mtok │
│ ❯ 4. arn:aws:bedrock:ap-northeast-1:123456789012:application-inference-profile/hdxk4zqkrcgh Custom model✔ │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Enter to confirm · Esc to exit
> hello
⏺ Hello! I'm Claude Code, ready to help you with your software engineering tasks. What would you like to work on today?
まとめ
以上、「Claude Code を Amazon Bedrock API Keys 経由で実行してみた」でした。
環境変数 1 つで切り替えできるのは、非常に楽ですね。AWS SSO 使っていないけど Short term なクレデンシャルで運用したいケースだと、うまくマッチしそうです。
このブログがどなたかの参考になれば幸いです。クラウド事業本部コンサルティング部のたかくに(@takakuni_)でした!