はじめに
こんにちは.
Claude Code を Amazon Bedrock と連携させて使ってみました.
インストールと設定方法の個人的な備忘録です.
前提
今回バージニア北部(us-east-1)を使用しているので,
バージニア北部リージョンでモデルアクセスをリクエストしておいてください.
Amazon Bedrock > Bedrock configurations > モデルアクセス
- 後述の ANTHROPIC_MODEL で使用するモデルアクセスをリクエストをする
- 3.7 Sonnet を使用する場合は「Claude 3.7 Sonnet」
- Sonnet 4 を使用する場合は「Claude Sonnet 4」
- Opus 4 を使用する場合は「Claude Opus 4」
- 今回触れませんが ANTHROPIC_SMALL_FAST_MODEL 用に「Claude 3.5 Haiku」もリクエストする
インストール
$ npm install -g @anthropic-ai/claude-code
$ claude --version
1.0.24 (Claude Code)
$ echo 'export CLAUDE_CODE_USE_BEDROCK=1' >> ~/.zshrc
# 3.7 Sonnet を使用する場合
# echo 'export ANTHROPIC_MODEL="us.anthropic.claude-3-7-sonnet-20250219-v1:0"' >> ~/.zshrc
# Sonnet 4 を使用する場合
$ echo 'export ANTHROPIC_MODEL="us.anthropic.claude-sonnet-4-20250514-v1:0"' >> ~/.zshrc
# Opus 4 を使用する場合
# echo 'export ANTHROPIC_MODEL="us.anthropic.claude-opus-4-20250514-v1:0"' >> ~/.zshrc
上記, zsh でなく bash を使用している場合は ~/.bashrc でも構いません.
起動
任意のディレクトリに移動して claude コマンドを実行します.
% AWS_PROFILE=default AWS_REGION=us-east-1 claude
╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: /Users/kawano/repositories/hoge │
╰───────────────────────────────────────────────────╯
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
Note: You have launched claude in your home directory. For the best experience, launch it in a project directory instead.
※ Tip: Use /memory to view and manage Claude memory
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ > Try "edit <filepath> to..." │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
? for shortcuts
起動できましたね.
claude コマンド実行時の環境変数 AWS_PROFILE などは適宜変更してください.
コストについて
> /cost
⎿ Total cost: $0.0000
Total duration (API): 0s
Total duration (wall): 2.5s
Total code changes: 0 lines added, 0 lines removed
Tokens: 0 input, 0 output, 0 cache read, 0 cache write
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ > │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
? for shortcuts
/cost で現在のセッションでのコストを確認できます.
下記もチェックしておいたほうがよさそうです.
Bedrock の料金
今回 ANTHROPIC_MODEL として Sonnet 4 を指定しました.
Opus 4 の場合, Sonnet 4 や 3.7 Sonnet の5倍かかるので気を付けて使っていきましょう.
プラグイン
IDE 用のプラグインも用意されているようです.
なお, 前述した @anthropic-ai/claude-code のインストール・設定を行った上で,
必要に応じてプラグインを導入してくださいませ.
さいごに
CLI だからこそ IDE に依存せず使用できて Good ですね.
AWS アカウントを持っている方で, Claude Code を試してみたい方にいいかもしれません.