

我們不再更新 Amazon Machine Learning 服務或接受新使用者。本文件可供現有使用者使用，但我們不再更新。如需詳細資訊，請參閱[什麼是 Amazon Machine Learning](https://docs.aws.amazon.com/machine-learning/latest/dg/what-is-amazon-machine-learning.html)。

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

# 控制 Amazon ML 資源的存取 - 使用 IAM
<a name="controlling-access-to-amazon-ml-resources-by-using-iam"></a>

AWS Identity and Access Management (IAM) 可讓您安全地控制使用者對 AWS 服務和資源的存取。使用 IAM，您可以建立和管理 AWS 使用者、群組和角色，並使用許可來允許和拒絕使用 IAM 搭配 Amazon Machine Learning (Amazon ML) 存取 AWS resources.By，您可以控制組織中的使用者是否可以使用特定 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/)》。

## IAM 政策語法
<a name="policy-syntax"></a>

 IAM 政策為包含一或多個陳述式的 JSON 文件。每個陳述式結構如下：

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

 政策陳述式包含下列元素：
+  **效果：**控制使用資源和 API 動作 (您稍後將於陳述式中指定) 的許可。有效值為 `Allow` 和 `Deny`。根據預設，IAM 使用者沒有使用資源和 API 動作的許可，因此所有請求均會遭到拒絕。明確 `Allow` 會覆寫預設值。明確 `Deny`會覆寫任何 `Allows`。
+  **動作**：您授予或拒絕許可的特定 API 動作。
+  **Resource** (資源)：受動作影響的資源。若要在陳述式中指定資源，您可以使用它的 Amazon Resource Name (ARN)。
+  **條件 (選用)**：控制政策生效的時機。

 若要簡化建立和管理 IAM 政策，您可以使用 AWS 政策產生器 和 IAM 政策模擬器。

## 指定 Amazon MLAmazon ML 的 IAM 政策動作
<a name="actions-for-amazon-ml"></a>

 在 IAM 政策陳述式中，您可以為支援 IAM 的任何服務指定 API 動作。當您為 Amazon ML API 動作建立政策陳述式時，請在 API 動作`machinelearning:`的名稱前面加上 ，如下列範例所示：
+ `machinelearning:CreateDataSourceFromS3`
+ `machinelearning:DescribeDataSources`
+ `machinelearning:DeleteDataSource`
+ `machinelearning:GetDataSource`

 若要在單一陳述式中指定多個動作，請用逗號分隔：

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

您也可以使用萬用字元指定多個動作。例如，您可以指定名稱開頭有 "Get" 文字的所有動作：

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

若要指定所有 Amazon ML 動作，請使用 \$1 萬用字元：

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

 如需 Amazon ML API 動作的完整清單，請參閱 [Amazon Machine Learning API 參考](https://docs.aws.amazon.com/machine-learning/latest/APIReference/)。

## 在 IAM 政策中指定 Amazon ML 資源ARNs
<a name="amazon-resource-names-arns-for-amazon-ml"></a>

 IAM 政策陳述式適用於一或多個資源。您可以根據資源的 ARN 來為政策指定資源。

 若要指定 Amazon ML 資源ARNs，請使用下列格式：

 "Resource": `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 MLs的範例政策
<a name="example-policies-for-amazon-ml"></a>

 **範例 1：允許使用者讀取機器學習資源中繼資料** 

以下政策允許使用者或群組透過對指定的資源執行 [DescribeDataSources](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_DescribeDataSources.html)、[DescribeMLModels](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_DescribeMLModels.html)、[DescribeBatchPredictions](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_DescribeBatchPredictions.html)、[DescribeEvaluations](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_DescribeEvaluations.html)、[GetDataSource](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_GetDataSource.html)、[GetMLModel](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_GetMLModel.html)、[GetBatchPrediction](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_GetBatchPrediction.html) 和 [GetEvaluation](https://docs.aws.amazon.com/machine-learning/latest/APIReference/API_GetEvaluation.html) 動作，以讀取資料來源、ML 模型、批次預測和評估的中繼資料。Describe\$1 操作許可不能限制在特定的資源上。

------
#### [ 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 MLaction** 

 下列政策允許使用者或群組使用任何 Amazon ML 動作。由於此政策會授予您所有機器學習資源的完整存取權，因此僅限管理員使用。

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

****  

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

------