Claude Code GitHub Actions - Anthropic を Amazon Bedrock と共に使用したときに調べたことの備忘録です。
目次
- AWS に Identity provider を作成する
- AWS に IAM Role を作成する
- Amazon Bedrock のモデルアクセスをリクエストする
- GitHub Actions のワークフローを設定する
- 使い方
AWS に Identity provider を作成する
Amazon Web Services での OpenID Connect の設定 - GitHub Docs を参考に Identity provider を作成します。
AWS に IAM Role を作成する
IAM Role の信頼ポリシーの例
AWS での OpenID Connect > ロールと信頼ポリシーの構成 | GitHub Docs を参考に IAM Role の信頼ポリシーを設定します。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::YOUR_AWS_ACCOUNT_ID:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
},
"StringLike": {
"token.actions.githubusercontent.com:sub": [
"repo:YOUR_ORG/YOUR_REPO_A:*",
"repo:YOUR_ORG/YOUR_REPO_B:*",
"repo:YOUR_ORG/YOUR_REPO_C:*"
]
}
}
}
]
}
YOUR_AWS_ACCOUNT_ID, YOUR_ORG, YOUR_REPO をご自身のものに置き換えてご利用ください。
上記のように利用できるリポジトリを制限しないと、他の人が使っている GitHub Actions で IAM Role を引き受けできる状態になり、知らないうちに誰かの Actions 経由で AWS が使われていた、というようなことが起きる可能性があります。
IAM Role の権限の例
Amazon Bedrock のアイデンティティベースのポリシー例 - Amazon Bedrock を参考に権限を設定します。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ModelInvocation",
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": "*"
}
]
}
Amazon Bedrock のモデルアクセスをリクエストする
以下のドキュメントを参考に Bedrock のモデルアクセスをリクエストします。この記事を作るときは、東京リージョンの Claude Sonnet 4 のアクセスをリクエストしました。
GitHub Actions のワークフローを設定する
github.com/anthropics/claude-code-action を参考に GitHub Actions の yaml ファイルを設定します。
name: Claude Assistant
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]
jobs:
claude-response:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: ap-northeast-1
- uses: anthropics/claude-code-action@beta
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
use_bedrock: "true"
model: apac.anthropic.claude-sonnet-4-20250514-v1:0
model は、さきほどリクエストをした、東京リージョンの Claude Sonnet 4 を設定しています。Claude Sonnet 4 のように inference profile を通じてのみ利用できる Model は、Model ID の前に apac
のようにリージョンを示す文字列をつける必要があります。リージョンを示す文字列は inference profile でサポートされているリージョンとモデル | Amazon Bedrock から調べることができます。
これを忘れると以下のようなエラーメッセージが出力されます。
API Error (***): 400 Invocation of model ID *** with on-demand throughput isn’t supported. Retry your request with the ID or ARN of an inference profile that contains this model.
また Claude Code GitHub Actions > Using with AWS Bedrock & Google Vertex AI - Anthropic では、Actions からリポジトリにアクセスするためにカスタム GitHub App を利用する方法が推奨されていましたが、今回は GITHUB_TOKEN による方式を選択しました。スコープが Actions に閉じていて影響が少なく、workflow で必要な情報が表現できて全体の見通しが良いのが理由です。Claude 公式の GitHub App も利用できるので、どれでも好きな方法を選択してよいと思います。
使い方
github.com/anthropics/claude-code-action#examples を参考に Issue や Pull request のコメントで @claude
とメンションをつけてタスクを依頼します。
@claude
Hello World と出力する bash スクリプトを作成してください
コメントをトリガに Actions が動いて AI がタスクを実行し、Issue コメントに結果を書いてくれます。コードを書く指示をした場合は AI がブランチを作ってその中でコードを書いてくれて、最終的にプルリクエストを作成するためのリンクが Issue に書き込まれるので、それを人間がクリックして、プルリクエストを作成する流れになります。