タイトルどおり。
課題
個人で管理しているAWS Organizations配下のAWSアカウントでAmazon BedrocksのAPIを呼び出したら以下のエラーが出てうまく呼び出せなかった。Amazon BedrocksのAPIはStrands Agents SDKから呼び出した。基盤モデルはAnthropicのClaude Sonnect 4である。
botocore.errorfactory.AccessDeniedException: An error occurred (AccessDeniedException) when calling the ConverseStream operation: User: arn:aws:sts::************:assumed-role/AWSReservedSSO_***_***/Demo_user is not authorized to perform: bedrock:InvokeModelWithResponseStream on resource: arn:aws:bedrock:ap-northeast-2::foundation-model/anthropic.claude-sonnet-4-20250514-v1:0 with an explicit deny in a service control policy └ Bedrock region: ap-northeast-1 └ Model id: apac.anthropic.claude-sonnet-4-20250514-v1:0
呼び出し元は手元で東京リージョン (ap-northeast-1) を指定しているが、呼び出したエンドポイントはクロスリージョン推論プロファイルのものなので apac というプレフィックスがついている。
クロスリージョンと名前のとおり ap-northeast-1 がリソース名についていないのは想定どおりだが、ap-northeast-2 もSCPで許可しているのに呼び出しが失敗する。
SCPは以下のように Condition 句で利用可能なリージョンを制限するように設定している。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "DenyAllOutsideAPAC", "Effect": "Deny", "NotAction": [ "iam:*", "cloudfront:*", "route53:*", "support:*", "aws-portal:*", "budgets:*", "health:*" ], "Resource": "*", "Condition": { "StringNotEquals": { "aws:RequestedRegion": [ "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "us-east-1", "us-west-2" ] } } } ] }
解決策
APACの全てのリージョンを許可する必要があった。 送信元リージョン単位に推論リクエスト送信先のリージョン一覧が公式ドキュメント(以下リンク先)に載っているので、 ap-northeast-1 に対応するリージョンを探せばよい。 今回のケースだと不足してた ap-south-[1|2], ap-southeast-[1|2|4] を許可したら通った。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "DenyAllOutsideAPAC", "Effect": "Deny", "NotAction": [ ... ], "Resource": "*", "Condition": { "StringNotEquals": { "aws:RequestedRegion": [ "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-south-2", "ap-southeast-1", "ap-southeast-2", "ap-southeast-4", "us-east-1", "us-west-2" ] } } } ] }
以上。