

我们不再更新 Amazon Machine Learning 服务，也不再接受新用户使用该服务。本文档可供现有用户使用，但我们不会再对其进行更新。有关更多信息，请参阅[什么是 Amazon Machine Learning](https://docs.aws.amazon.com/machine-learning/latest/dg/what-is-amazon-machine-learning.html)。

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

# 使用 IAM 控制对 Amazon ML 资源的访问
<a name="controlling-access-to-amazon-ml-resources-by-using-iam"></a>

AWS Identity and Access Management (IAM) 使您能够安全地控制用户对 AWS 服务和资源的访问权限。使用 IAM 可以创建和管理 AWS 用户、组和角色，您还可以使用权限来允许或拒绝对 AWS 资源的访问。借助 IAM 和 Amazon Machine Learning (Amazon ML)，可以控制组织中的用户是否可以使用特定 AWS 资源以及他们是否可以使用特定 Amazon ML API 操作来执行任务。

 IAM 让您能够：
+  在您的 AWS 账户下创建用户和组。
+  为您的 AWS 账户下的每个用户分配唯一的安全凭证 
+  控制每个用户使用 AWS 资源执行任务的权限 
+  轻松地在您 AWS 账户中与用户共享您的 AWS 资源 
+  创建 AWS 账户角色并管理其权限，以定义可以代入这些角色的用户或服务 
+ 在 IAM 中创建角色和管理权限，控制代入该角色的实体或 AWS 服务可执行的操作。您也可以定义由哪个实体承担该角色。



 如果您的组织已有 IAM 身份，您可以使用它们来授予使用 AWS 资源执行任务的权限。

有关 IAM 的更多信息，请参阅《IAM 用户指南》[https://docs.aws.amazon.com/IAM/latest/UserGuide/](https://docs.aws.amazon.com/IAM/latest/UserGuide/)。

## IAM 策略语法
<a name="policy-syntax"></a>

 IAM 策略是包含一个或多个语句的 JSON 文档。每个语句具有以下结构：

```
{
    "Statement":[{
        "Effect":"effect",
        "Action":"action",
        "Resource":"arn",
        "Condition":{
            "condition operator":{
                "key":"value"
            }
        }
    }]
}
```

 策略语句包含以下元素：
+  **Effect**：控制使用您在语句后面指定的资源和 API 操作的权限。有效值为 `Allow`和 `Deny`。在默认情况下，IAM 用户没有使用资源和 API 操作的许可，因此，所有请求均会被拒绝。显式 `Allow` 将覆盖默认值。显式 `Deny` 将覆盖任意 `Allows`。
+  **Action**：您对其授予或拒绝权限的特定 API 操作。
+  **Resource**：受操作影响的资源。要在语句中指定资源，您可使用其 Amazon 资源名称 (ARN)。
+  **条件（可选）**：控制您的策略何时生效。

 为简化 IAM 策略的创建和管理，您可以使用 AWS 策略生成器和 IAM 策略模拟器。

## 为 Amazon ML 指定 IAM 策略操作
<a name="actions-for-amazon-ml"></a>

 在 IAM 策略语句中，您可以为支持 IAM 的任何服务指定 API 操作。在您为 Amazon ML API 操作创建策略语句时，请附加 `machinelearning:` 到 API 操作的名称，如下例中所示：
+ `machinelearning:CreateDataSourceFromS3`
+ `machinelearning:DescribeDataSources`
+ `machinelearning:DeleteDataSource`
+ `machinelearning:GetDataSource`

 要在单个语句中指定多项操作，请使用逗号将它们隔开：

```
"Action": ["machinelearning:action1", "machinelearning:action2"]
```

您也可以使用通配符指定多项操作。例如，您可以指定名称以单词“Get”开头的所有操作：

```
"Action": "machinelearning:Get*"
```

要指定所有 Amazon ML 操作，请使用 \* 通配符：

```
"Action": "machinelearning:*"
```

 有关 Amazon ML API 操作的完整列表，请参阅 [Amazon Machine Learning API 参考](https://docs.aws.amazon.com/machine-learning/latest/APIReference/)。

## 在 IAM 策略中指定 Amazon ML 资源的 ARN
<a name="amazon-resource-names-arns-for-amazon-ml"></a>

 IAM 策略语句应用到一个或多个资源。您可以按 ARN 为策略指定资源。

 要为 Amazon ML 资源指定 ARN，请使用以下格式：

 "资源": `arn:aws:machinelearning:region:account:resource-type/identifier `

 以下示例显示如何指定通用 ARN。

 数据源 ID：`my-s3-datasource-id `

```
"Resource":
arn:aws:machinelearning:<region>:<your-account-id>:datasource/my-s3-datasource-id
```

 ML 模型 ID：`my-ml-model-id `

```
"Resource":
arn:aws:machinelearning:<region>:<your-account-id>:mlmodel/my-ml-model-id
```

 批量预测 ID：`my-batchprediction-id `

```
"Resource":
arn:aws:machinelearning:<region>:<your-account-id>:batchprediction/my-batchprediction-id
```

 评估 ID：`my-evaluation-id `

```
"Resource": arn:aws:machinelearning:<region>:<your-account-id>:evaluation/my-evaluation-id
```

## Amazon ML 的策略示例
<a name="example-policies-for-amazon-ml"></a>

 **示例 1：允许用户读取机器学习资源元数据** 

以下策略允许用户或群组通过对指定资源执行 [desc [DescribeDataSources](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_DescribeDataSources.html)ribemlModel、、、、getmlM](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_GetMLModel.html) odel 和操作来读取数据源、机器学习[模型[DescribeBatchPredictions[DescribeEvaluations[GetDataSource](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_GetDataSource.html)](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_DescribeEvaluations.html)](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_DescribeBatchPredictions.html)](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_DescribeMLModels.html)、批量预测和评估的元数据。[GetBatchPrediction[GetEvaluation](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_GetEvaluation.html)](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_GetBatchPrediction.html)Describe \* 操作权限无法限定为特定资源。

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

****  

```
{ "Version":"2012-10-17",		 	 	  "Statement": [ { "Effect": "Allow", "Action": [
    "machinelearning:Get*" ], "Resource": [
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:datasource/S3-DS-ID1",
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:datasource/REDSHIFT-DS-ID1",
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:mlmodel/ML-MODEL-ID1",
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:batchprediction/BP-ID1",
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:evaluation/EV-ID1"
    ] }, { "Effect": "Allow", "Action": [ "machinelearning:Describe*" ], "Resource": [ "*" ] } ]
    }
```

------

 **示例 2：允许用户创建机器学习资源** 

 以下策略允许用户或组通过 `CreateDataSourceFromS3`、`CreateDataSourceFromRedshift`、`CreateDataSourceFromRDS`、`CreateMLModel`、`CreateBatchPrediction` 和 `CreateEvaluation` 操作，创建机器学习数据源、ML 模型、批量预测和评估。您不能将这些操作的权限限制为特定资源。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "machinelearning:CreateDataSourceFrom*",
                "machinelearning:CreateMLModel",
                "machinelearning:CreateBatchPrediction",
                "machinelearning:CreateEvaluation"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
```

------

 **示例 3：允许用户创建和删除实时终端节点以及对 ML 模型执行实时预测** 

 以下策略允许用户或组对该模型执行 `CreateRealtimeEndpoint`、`DeleteRealtimeEndpoint` 和 `Predict` 操作，以创建和删除实时终端节点以及为特定 ML 模型执行实时预测。

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

****  

```
{ "Version":"2012-10-17",		 	 	  "Statement": [ { "Effect": "Allow", "Action": [
    "machinelearning:CreateRealtimeEndpoint", "machinelearning:DeleteRealtimeEndpoint",
    "machinelearning:Predict" ], "Resource": [
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:mlmodel/ML-MODEL"
    ] } ] }
```

------

 **示例 4：允许用户更新和删除特定资源** 

 以下策略通过向用户或组授予执行 `UpdateDataSource`、`UpdateMLModel`、`UpdateBatchPrediction`、`UpdateEvaluation`、`DeleteDataSource`、`DeleteMLModel`、`DeleteBatchPrediction` 和 `DeleteEvaluation` 操作的权限，允许用户或组在您的 AWS 账户中更新和删除特定资源。

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

****  

```
{ "Version":"2012-10-17",		 	 	  "Statement": [ { "Effect": "Allow", "Action": [
    "machinelearning:Update*", "machinelearning:DeleteDataSource", "machinelearning:DeleteMLModel",
    "machinelearning:DeleteBatchPrediction", "machinelearning:DeleteEvaluation" ], "Resource": [
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:datasource/S3-DS-ID1",
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:datasource/REDSHIFT-DS-ID1",
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:mlmodel/ML-MODEL-ID1",
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:batchprediction/BP-ID1",
        "arn:aws:machinelearning:{{us-east-1}}:{{123456789012}}:evaluation/EV-ID1"
    ] } ] }
```

------

 **示例 5：允许任意 Amazon ML 操作** 

 以下策略允许用户或组使用任意 Amazon ML 操作。由于此策略会授予对您的机器学习资源的全部访问权限，您应该将其限制为仅对管理员可用。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "machinelearning:*"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
```

------