本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭ModifyCluster
配 AWS 開發套件或 CLI 使用
下列程式碼範例會示範如何使用ModifyCluster
。
- CLI
-
- AWS CLI
-
將「安全群組」與 ClusterThis 範例產生關聯,顯示如何將叢集安全性群組與指定的叢集產生關聯。命令:
aws redshift modify-cluster --cluster-identifier mycluster --cluster-security-groups mysecuritygroup
修改「維護時段」,以 ClusterThis 顯示如何將叢集的每週偏好維護時段變更為從星期日晚上 11:15 開始至少 4 小時的時段,並在星期一凌晨 3:15 結束。命令:
aws redshift modify-cluster --cluster-identifier mycluster --preferred-maintenance-window Sun:23:15-Mon:03:15
變更主要密碼的 ClusterThis 範例顯示如何變更叢集的主要密碼。命令:
aws redshift modify-cluster --cluster-identifier mycluster --master-user-password A1b2c3d4
-
如需 API 詳細資訊,請參閱AWS CLI 命令參考ModifyCluster
中的。
-
- Java
-
- 適用於 Java 2.x 的 SDK
-
注意
還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫
。 修改叢集。
public static void modifyCluster(RedshiftClient redshiftClient, String clusterId) { try { ModifyClusterRequest modifyClusterRequest = ModifyClusterRequest.builder() .clusterIdentifier(clusterId) .preferredMaintenanceWindow("wed:07:30-wed:08:00") .build(); ModifyClusterResponse clusterResponse = redshiftClient.modifyCluster(modifyClusterRequest); System.out.println("The modified cluster was successfully modified and has " + clusterResponse.cluster().preferredMaintenanceWindow() + " as the maintenance window"); } catch (RedshiftException e) { System.err.println(e.getMessage()); System.exit(1); } }
-
如需 API 詳細資訊,請參閱 AWS SDK for Java 2.x API 參考ModifyCluster中的。
-
- JavaScript
-
- 適用於 JavaScript (v3) 的開發套件
-
注意
還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫
。 建立用戶端。
import { RedshiftClient } from "@aws-sdk/client-redshift"; // Set the AWS Region. const REGION = "REGION"; //Set the Redshift Service Object const redshiftClient = new RedshiftClient({ region: REGION }); export { redshiftClient };
修改叢集。
// Import required AWS SDK clients and commands for Node.js import { ModifyClusterCommand } from "@aws-sdk/client-redshift"; import { redshiftClient } from "./libs/redshiftClient.js"; // Set the parameters const params = { ClusterIdentifier: "CLUSTER_NAME", MasterUserPassword: "NEW_MASTER_USER_PASSWORD", }; const run = async () => { try { const data = await redshiftClient.send(new ModifyClusterCommand(params)); console.log("Success was modified.", data); return data; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
-
如需 API 詳細資訊,請參閱 AWS SDK for JavaScript API 參考ModifyCluster中的。
-
- Kotlin
-
- 適用於 Kotlin 的 SDK
-
注意
還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫
。 修改叢集。
suspend fun modifyCluster(clusterId: String?) { val modifyClusterRequest = ModifyClusterRequest { clusterIdentifier = clusterId preferredMaintenanceWindow = "wed:07:30-wed:08:00" } RedshiftClient { region = "us-west-2" }.use { redshiftClient -> val clusterResponse = redshiftClient.modifyCluster(modifyClusterRequest) println( "The modified cluster was successfully modified and has ${clusterResponse.cluster?.preferredMaintenanceWindow} as the maintenance window", ) } }
-
有關 API 的詳細信息,請參閱 AWS SDK ModifyCluster
中的 Kotlin API 參考。
-
- Python
-
- 適用於 Python (Boto3) 的 SDK
-
注意
還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫
。 class RedshiftWrapper: """ Encapsulates Amazon Redshift cluster operations. """ def __init__(self, redshift_client): """ :param redshift_client: A Boto3 Redshift client. """ self.client = redshift_client def modify_cluster(self, cluster_identifier, preferred_maintenance_window): """ Modifies a cluster. :param cluster_identifier: The cluster identifier. :param preferred_maintenance_window: The preferred maintenance window. """ try: self.client.modify_cluster( ClusterIdentifier=cluster_identifier, PreferredMaintenanceWindow=preferred_maintenance_window, ) except ClientError as err: logging.error( "Couldn't modify a cluster. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
下面的代碼實例化對 RedshiftWrapper 象。
client = boto3.client("redshift") redhift_wrapper = RedshiftWrapper(client)
-
如需 API 的詳細資訊,請參閱AWS 開發套件ModifyCluster中的 Python (博托 3) API 參考。
-
如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱搭配 AWS SDK 使用此服務。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。