New user sign up using AWS Builder ID
New user sign up using AWS Builder ID is currently unavailable on re:Post. To sign up, please use the AWS Management Console instead.
如何疑難排解 Amazon Bedrock 中的 InvokeModel API 錯誤?
我想解決在我呼叫 InvokeModel API 時遇到的 AccessDeniedException 或 ValidationException 錯誤。
解決方法
當您在 Amazon Bedrock 中呼叫 **InvokeModel ** API 時,您可能會遇到拒絕存取或驗證錯誤。當 API 無法存取嘗試調用的基本模型時,會發生這些錯誤。如果您的帳戶沒有執行作業所需的權限,也可能會出現錯誤。
模型存取錯誤
錯誤: 「An error occurred (AccessDeniedException) when calling the InvokeModel operation: Your account is not authorized to invoke this API operation.」(呼叫 InvokeModel 作業時發生錯誤 (AccessDeniedException):您的帳戶未獲得授權調用此 API 作業。)
-or-
錯誤: 「An error occurred (AccessDeniedException) when calling the InvokeModel operation: You don't have access to the model with the specified model ID.」(呼叫 InvokeModel 作業時發生錯誤 (AccessDeniedException):您無法存取具有指定模型 ID 的模型。)
這些錯誤表示您沒有嘗試使用 API 調用的模型存取權。
若要解決此問題,請完成下列步驟:
- 請確定模型在您調用 API 的同一 AWS 區域中提供。如需詳細資訊,請參閱依 AWS 區域的模型支援。
- 確認存取狀態設定為已授予。如需詳細資訊,請參閱新增模型存取權。
注意: 這是 AWS 區域的一次性設定。
AWS Identity and Access Management (IAM) 權限錯誤
錯誤: 「AccessDeniedException: An error occurred (AccessDeniedException) when calling the InvokeModel operation: User: <> is not authorized to perform: bedrock:InvokeModel on resource: <> with an explicit deny in an identity-based policy.」(AccessDeniedException:呼叫 InvokeModel 作業時發生錯誤 (AccessDeniedException):使用者:<> 未獲得在以身份為基礎的政策中明確拒絕於資源:<> 上執行:bedrock:InvokeModel 的授權。)
-or-
錯誤: 「AccessDeniedException: An error occurred (AccessDeniedException) when calling the InvokeModel operation: User: <> is not authorized to perform: bedrock:InvokeModel on resource: <> because no identity-based policy allows the bedrock:InvokeModel action.」(AccessDeniedException:呼叫 InvokeModel 作業時發生錯誤 (AccessDeniedException):使用者:<> 未獲得在資源:<> 上執行:bedrock:InvokeModel 的授權,因為沒有以身分為基礎的政策允許 bedrock:InvokeModel 動作。)
這些錯誤表示嘗試調用 API 的 IAM 使用者或角色缺乏所需的權限。
若要解決錯誤,請確認符合下列條件:
-
用於調用此 API 的 IAM 使用者或角色具有必要的「允許」動作,如下所示。如需詳細資訊,請參閱 Amazon Bedrock 如何與 IAM 搭配使用。
{ "Version": "2012-10-17", "Statement": { "Sid": "AllowInference", "Effect": "Allow", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream" ], "Resource": "arn:aws:bedrock:*::foundation-model/model-id" } }
-
確認 AWS Organizations 層級的服務控制政策 (SCP) 中,沒有指定明確的拒絕動作。「拒絕」動作可能會影響權限。
API 動作錯誤
錯誤: 「ValidationException: An error occurred (ValidationException) when calling the InvokeModel operation: The requested operation is not recognized by the service.」(ValidationException:呼叫 InvokeModel 作業時發生錯誤 (ValidationException):服務無法識別要求的作業。)
當您使用錯誤的 API 動作時,會出現此錯誤。
若要解決此問題,請在 API 呼叫中指定 bedrock-runtime 作為服務。如需詳細資訊,請參閱動作與 BedrockRuntime。
SDK 版本錯誤
錯誤: 「UnknownServiceError: Unknown service: 'bedrock-runtime」(UnknownServiceError:未知服務:'bedrock-runtime)
當您使用不相容的 Boto3 SDK 版本呼叫 InvokeModel API 時,會出現此錯誤。
若要解決此問題,請將 boto3/botocore SDK 升級至最新版本。如需詳細資訊,請參閱 GitHub 網站上的 boto3/CHANGELOG.rst。
帳戶限制錯誤
錯誤: 「An error occurred (ValidationException) when calling the InvokeModel operation: Operation not allowed」(呼叫 InvokeModel 作業時發生錯誤 (ValidationException):不允許操作)
當您的 AWS 帳戶有安全限制時,會出現此錯誤。
若要解決此問題,請在 AWS Support 中開啟支援案例。如需詳細資訊,請參閱建立支援案例。
相關內容
- 已提問 5 個月前lg...
- 已提問 4 個月前lg...
- 已提問 1 個月前lg...
- AWS 官方已更新 10 個月前
- AWS 官方已更新 2 個月前
- AWS 官方已更新 2 年前
- AWS 官方已更新 3 個月前