

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 推論設定檔的必要條件
<a name="inference-profiles-prereq"></a>

請先檢查您是否符合下列必要條件後，才可使用推論設定檔：
+ 您的角色可以存取推論設定檔 API 動作。如果您的角色已連接 [AmazonBedrockFullAccess](security-iam-awsmanpol.md#security-iam-awsmanpol-AmazonBedrockFullAccess)AWS 受管政策，您可以略過此步驟。若否，請執行下列操作：

  1. 遵循[建立 IAM 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)中的步驟，並建立下列政策，允許角色執行推論設定檔相關的動作，並使用所有基礎模型和推論設定檔執行模型推論。

------
#### [ JSON ]

****  

     ```
     {
         "Version":"2012-10-17",		 	 	 
         "Statement": [
             {
                 "Effect": "Allow",
                 "Action": [
                     "bedrock:InvokeModel*",
                     "bedrock:CreateInferenceProfile"
                 ],
                 "Resource": [
                     "arn:aws:bedrock:*::foundation-model/*",
                     "arn:aws:bedrock:*:*:inference-profile/*",
                     "arn:aws:bedrock:*:*:application-inference-profile/*"
                 ]
             },
             {
                 "Effect": "Allow",
                 "Action": [
                     "bedrock:GetInferenceProfile",
                     "bedrock:ListInferenceProfiles",
                     "bedrock:DeleteInferenceProfile",
                     "bedrock:TagResource",
                     "bedrock:UntagResource",
                     "bedrock:ListTagsForResource"
                 ],
                 "Resource": [
                     "arn:aws:bedrock:*:*:inference-profile/*",
                     "arn:aws:bedrock:*:*:application-inference-profile/*"
                 ]
             }
         ]
     }
     ```

------

     (選用) 您可以透過以下方式限制角色的存取：
     + 若要限制角色可以執行的 API 動作，請將 `Action` 欄位中的清單修改為僅包含您要允許存取的 [API 操作](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html#amazonbedrock-actions-as-permissions)。
     + 若要限制角色對特定推論設定檔的存取，請將 `Resource` 清單修改為僅包含您要允許存取的[推論設定檔](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html#amazonbedrock-resources-for-iam-policies)和基礎模型。系統定義的推論設定檔開頭為 `inference-profile`，而應用程式推論設定檔開頭為 `application-inference-profile`。
**重要**  
當您在第一個陳述式的 `Resource` 欄位中指定推論設定檔時，還必須在與其相關聯的每個區域中指定基礎模型。
     + 若要限制使用者存取，以便他們只能透過推論設定檔調用基礎模型，請新增 `Condition` 欄位並使用 `aws:InferenceProfileArn` [條件金鑰](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html#amazonbedrock-policy-keys)。指定您要篩選存取權的推論設定檔。此條件可以包含在範圍為 `foundation-model` 資源的陳述式中。
     + 例如，您可以將下列政策連接至角色，使其只能透過 us-west-2 中帳戶 {{111122223333}} 中的美國 Anthropic Claude 3 Haiku 推論設定檔調用 Anthropic Claude 3 Haiku 模型：

------
#### [ JSON ]

****  

       ```
       {
           "Version":"2012-10-17",		 	 	 
           "Statement": [
               {
                   "Effect": "Allow",
                   "Action": [
                       "bedrock:InvokeModel*"
                   ],
                   "Resource": [
                       "arn:aws:bedrock:us-west-2:{{111122223333}}:inference-profile/us.anthropic.claude-3-haiku-20240307-v1:0"
                   ]
               },
               {
                   "Effect": "Allow",
                   "Action": [
                       "bedrock:InvokeModel*"
                   ],
                   "Resource": [
                       "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-haiku-20240307-v1:0",
                       "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-haiku-20240307-v1:0"
                   ],
                   "Condition": {
                       "StringLike": {
                           "bedrock:InferenceProfileArn": "arn:aws:bedrock:us-west-2:{{111122223333}}:inference-profile/us.anthropic.claude-3-haiku-20240307-v1:0"
                       }
                   }
               }
           ]
       }
       ```

------
     + 例如，您可以將下列政策連接至角色，使其只能透過 us-east-2 (美國東部 (俄亥俄)) 中帳戶 111122223333 中的全域 Claude Sonnet 4 推論設定檔調用 Anthropic Claude Sonnet 4 模型。

------
#### [ JSON ]

****  

       ```
       {
           "Version":"2012-10-17",		 	 	 
           "Statement": [
               {
                   "Effect": "Allow",
                   "Action": [
                       "bedrock:InvokeModel*"
                   ],
                   "Resource": [
                       "arn:aws:bedrock:us-east-2:111122223333:inference-profile/global.anthropic.claude-sonnet-4-20250514-v1:0"
                   ]
               },
               {
                   "Effect": "Allow",
                   "Action": [
                       "bedrock:InvokeModel*"
                   ],
                   "Resource": [
                       "arn:aws:bedrock:us-east-2::foundation-model/anthropic.claude-sonnet-4-20250514-v1:0",
                       "arn:aws:bedrock:::foundation-model/anthropic.claude-sonnet-4-20250514-v1:0"
                   ],
                   "Condition": {
                       "StringLike": {
                           "bedrock:InferenceProfileArn": "arn:aws:bedrock:us-east-2:111122223333:inference-profile/global.anthropic.claude-sonnet-4-20250514-v1:0"
                       }
                   }
               }
           ]
       }
       ```

------
     + 您也可以透過新增明確拒絕 `StringEquals` 條件來檢查請求內容索引鍵 `aws:RequestedRegion` 是否等於未指定，藉此限制使用全域 Claude Sonnet 4 推論設定檔。由於符合 `StringEquals`，拒絕會覆寫任何允許並封鎖推論請求的全域路由。

       ```
       {
           "Effect": "Deny",
           "Action": [
               "bedrock:InvokeModel*"
           ],
           "Resource": "*",
           "Condition": {
               "StringEquals": {
                   "aws:RequestedRegion": "unspecified"
               }
           }
       },
       ```

  1. 請依照[新增及移除 IAM 身分許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)中的步驟，將政策連接至角色，以授予角色檢視和使用所有推論設定檔的許可。
+ 您已在要呼叫推論設定檔的區域中，請求存取您所要使用推論設定檔中定義的模型。