

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊，請參閱[部落格文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

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

# 將 IAM 角色與叢集建立關聯
<a name="copy-unload-iam-role-associating-with-clusters"></a>

建立 IAM 角色來授權 Amazon Redshift 代表您存取其他 AWS 服務後，您必須將該角色與 Amazon Redshift 叢集相關聯。您必須執行這項操作，才能使用該角色來載入或卸載資料。

## 將 IAM 角色與叢集建立關聯所需的許可
<a name="copy-unload-iam-role-associating-with-clusters-perms"></a>

若要將 IAM 角色與叢集相關聯，使用者必須擁有該 IAM 角色的 `iam:PassRole` 許可。管理員可以運用此許可，限制使用者可將哪些 IAM 角色與 Amazon Redshift 叢集相關聯。我們建議的最佳實務是，將許可政策連接到 IAM 角色，然後根據需要將其指派給使用者和群組。如需詳細資訊，請參閱 [Amazon Redshift 中的身分和存取管理](https://docs.aws.amazon.com/redshift/latest/mgmt/redshift-iam-authentication-access-control.html)。

以下範例顯示可連接到使用者的 IAM 政策，以允許使用者採取下列動作：
+ 取得該使用者帳戶所擁有之所有 Amazon Redshift 叢集的詳細資訊。
+ 將任何三個 IAM 角色與兩個 Amazon Redshift 叢集中的任一個相關聯。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "redshift:DescribeClusters",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                 "redshift:ModifyClusterIamRoles",
                 "redshift:CreateCluster"
            ],
            "Resource": [
                 "arn:aws:redshift:us-east-1:123456789012:cluster:my-redshift-cluster",
                 "arn:aws:redshift:us-east-1:123456789012:cluster:my-second-redshift-cluster"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": [
                "arn:aws:iam::123456789012:role/MyRedshiftRole",
                "arn:aws:iam::123456789012:role/SecondRedshiftRole",
                "arn:aws:iam::123456789012:role/ThirdRedshiftRole"
             ]
        }
    ]
}
```

------

使用者取得適當的許可後，該使用者可以將 IAM 角色與 Amazon Redshift 叢集相關聯。然後，IAM 角色就能使用 COPY 或 UNLOAD 命令，或是其他 Amazon Redshift 命令。

如需 IAM 政策的相關資訊，請參閱《IAM 使用者指南》**中的 [IAM 政策概觀](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html)。

## 管理 IAM 角色與叢集的關聯
<a name="managing-iam-role-association-with-cluster"></a>

您可以在建立叢集時將 IAM 角色與 Amazon Redshift 叢集相關聯。您也可以修改現有的叢集，並新增或移除一或多個 IAM 角色關聯。

請注意以下事項：
+ 您可建立關聯的 IAM 角色數量上限需符合配額。
+ IAM 角色可以與多個 Amazon Redshift 叢集相關聯。
+ 只有在 IAM 角色和叢集都屬於相同 AWS 帳戶時，IAM 角色才能與 Amazon Redshift 叢集建立關聯。

您可在主控台中使用下列程序管理叢集的 IAM 角色關聯。

**管理 IAM 角色關聯**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/redshiftv2/](https://console.aws.amazon.com/redshiftv2/)：// 開啟 Amazon Redshift 主控台。

1. 在導覽功能表上，選擇**叢集**，然後選擇您要更新的叢集。

1. 針對 **Actions (動作)**，選擇 **Manage IAM roles (管理 IAM 角色)** 以顯示與叢集相關聯的目前 IAM 角色清單。

1. 在 **Manage IAM roles (管理 IAM 角色)** 頁面上，選擇要新增的可用 IAM 角色，然後選擇 **Add IAM role (新增 IAM 角色)**。

1. 選擇 **Done (完成)** 以儲存變更。

您可以使用 AWS CLI 下列方法，透過 管理叢集的 IAM 角色關聯。

若要在建立叢集時將 IAM 角色與叢集相關聯，請用 `--iam-role-arns` 命令的 `create-cluster` 參數指定 IAM 角色的 Amazon Resource Name (ARN)。您在呼叫 `create-cluster` 命令時可新增的 IAM 角色數量上限需符合配額。

IAM 角色與 Amazon Redshift 叢集的相關聯和取消關聯是非同步的程序。您可呼叫 `describe-clusters` 命令，以取得所有 IAM 角色叢集關聯的狀態。

以下範例將兩個 IAM 角色與名為 `my-redshift-cluster` 的新建立叢集相關聯。

```
aws redshift create-cluster \
    --cluster-identifier "my-redshift-cluster" \
    --node-type "ra3.4xlarge" \
    --number-of-nodes 16 \
    --iam-role-arns "arn:aws:iam::123456789012:role/RedshiftCopyUnload" \
                    "arn:aws:iam::123456789012:role/SecondRedshiftRole"
```

若要將 IAM 角色與現有的 Amazon Redshift 叢集建立關聯，請在 `modify-cluster-iam-roles` 命令的 `--add-iam-roles` 參數中，指定 IAM 角色的 Amazon Resource Name (ARN)。您在呼叫 `modify-cluster-iam-roles` 命令時可新增的 IAM 角色數量上限需符合配額。

以下範例將一個 IAM 角色與名為 `my-redshift-cluster` 的現有叢集相關聯。

```
aws redshift modify-cluster-iam-roles \
    --cluster-identifier "my-redshift-cluster" \
    --add-iam-roles "arn:aws:iam::123456789012:role/RedshiftCopyUnload"
```

若要將 IAM 角色與叢集取消關聯，請用 `modify-cluster-iam-roles` 命令的 `--remove-iam-roles` 參數指定 IAM 角色的 ARN。`modify-cluster-iam-roles`您在呼叫 `modify-cluster-iam-roles` 命令時可移除的 IAM 角色數量上限需符合配額。

下列範例會從名為 的叢集中移除`123456789012` AWS 帳戶 IAM 角色的關聯`my-redshift-cluster`。

```
aws redshift modify-cluster-iam-roles \
    --cluster-identifier "my-redshift-cluster" \
    --remove-iam-roles "arn:aws:iam::123456789012:role/RedshiftCopyUnload"
```

### 使用 列出叢集的 IAM 角色關聯 AWS CLI
<a name="w2aac37c30c30c35c31b7b9c29"></a>

若要列出與 Amazon Redshift 叢集相關聯的所有 IAM 角色，以及 IAM 角色關聯的狀態，請呼叫 `describe-clusters` 命令。`IamRoles` 清單會傳回與叢集關聯之每個 IAM 角色的 ARN，如下列輸出範例所示。

已經與叢集相關聯的角色狀態會顯示為 `in-sync`。正在與叢集相關聯的角色狀態會顯示為 `adding`。正在與叢集取消關聯的角色狀態會顯示為 `removing`。

```
{
    "Clusters": [
        {
            "ClusterIdentifier": "my-redshift-cluster",
            "NodeType": "ra3.4xlarge",
            "NumberOfNodes": 16,
            "IamRoles": [
                {
                    "IamRoleArn": "arn:aws:iam::123456789012:role/MyRedshiftRole",
                    "IamRoleApplyStatus": "in-sync"
                },
                {
                    "IamRoleArn": "arn:aws:iam::123456789012:role/SecondRedshiftRole",
                    "IamRoleApplyStatus": "in-sync"
                }
            ],
            ...
        },
        {
            "ClusterIdentifier": "my-second-redshift-cluster",
            "NodeType": "ra3.4xlarge",
            "NumberOfNodes": 10,
            "IamRoles": [
                {
                    "IamRoleArn": "arn:aws:iam::123456789012:role/MyRedshiftRole",
                    "IamRoleApplyStatus": "in-sync"
                },
                {
                    "IamRoleArn": "arn:aws:iam::123456789012:role/SecondRedshiftRole",
                    "IamRoleApplyStatus": "in-sync"
                },
                {
                    "IamRoleArn": "arn:aws:iam::123456789012:role/ThirdRedshiftRole",
                    "IamRoleApplyStatus": "in-sync"
                }
            ],
            ...
        }
    ]
}
```

如需使用 的詳細資訊 AWS CLI，請參閱 *[AWS CLI 使用者指南](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)*。