将 ModifyCluster
与 Amazon SDK 或 CLI 配合使用
以下代码示例演示如何使用 ModifyCluster
。
- CLI
-
- Amazon CLI
-
将安全组与集群关联 此示例演示了如何将群集安全组与指定的集群相关联。命令:
aws redshift modify-cluster --cluster-identifier mycluster --cluster-security-groups mysecuritygroup
修改集群的维护时段 此示例演示了如何将集群的每周首选维护时段更改为最少四小时的时段,从周日晚上 11:15 开始,到周一凌晨 3:15 结束。命令:
aws redshift modify-cluster --cluster-identifier mycluster --preferred-maintenance-window Sun:23:15-Mon:03:15
更改集群的主密码 此示例演示了如何更改集群的主密码。命令:
aws redshift modify-cluster --cluster-identifier mycluster --master-user-password A1b2c3d4
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ModifyCluster
。
-
- Java
-
- SDK for Java 2.x
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 修改集群。
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 详细信息,请参阅《Amazon SDK for Java 2.x API 参考》中的 ModifyCluster。
-
- JavaScript
-
- SDK for JavaScript (v3)
-
注意
在 GitHub 上查看更多内容。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 创建客户端。
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 详细信息,请参阅《Amazon SDK for JavaScript API 参考》中的 ModifyCluster。
-
- Kotlin
-
- 适用于 Kotlin 的 SDK
-
注意
在 GitHub 上查看更多内容。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 修改集群。
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 详细信息,请参阅《Amazon SDK for Kotlin API 参考》中的 ModifyCluster
。
-
- Python
-
- SDK for Python(Boto3)
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 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 的详细信息,请参阅《Amazon SDK for Python(Boto3)API 参考》中的 ModifyCluster。
-
有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将此服务与 Amazon SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。