

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 推理配置文件的先决条件
<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}}中的美国AnthropicClaude 3 Haiku推理配置文件调用AnthropicClaude 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"
                       }
                   }
               }
           ]
       }
       ```

------
     + 您还可以通过添加明确的 Deny 操作来限制全局 Claude Sonnet 4 推理配置文件的使用，其 `StringEquals` 条件用于检查请求上下文密钥 `aws:RequestedRegion` 是否等于 unspecified。由于匹配了 `StringEquals`，因此 Deny 操作会覆盖任何 Allow，并阻止推理请求的全局路由。

       ```
       {
           "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)中的步骤将策略附加到某个角色，以授予该角色查看和使用所有推理配置文件的权限。
+ 您已请求获取要使用的推理配置文件中所定义的模型，以及要在其中调用推理配置文件的区域的访问权限。