Gunakan ModifyCluster dengan AWS SDK atau CLI - AWS SDKContoh Kode

Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan ModifyCluster dengan AWS SDK atau CLI

Contoh kode berikut menunjukkan cara menggunakanModifyCluster.

CLI
AWS CLI

Mengaitkan Grup Keamanan dengan ClusterThis contoh menunjukkan cara mengaitkan grup keamanan klaster dengan Cluster.command yang ditentukan:

aws redshift modify-cluster --cluster-identifier mycluster --cluster-security-groups mysecuritygroup

Ubah Jendela Pemeliharaan untuk ClusterThis menunjukkan cara mengubah jendela pemeliharaan pilihan mingguan untuk cluster menjadi jendela minimum empat jam mulai hari Minggu pukul 11:15, dan berakhir Senin pukul 3:15 pagi. Perintah:

aws redshift modify-cluster --cluster-identifier mycluster --preferred-maintenance-window Sun:23:15-Mon:03:15

Ubah Kata Sandi Master untuk ClusterThis contoh menunjukkan cara mengubah kata sandi master untuk cluster.Command:

aws redshift modify-cluster --cluster-identifier mycluster --master-user-password A1b2c3d4
  • Untuk API detailnya, lihat ModifyClusterdi Referensi AWS CLI Perintah.

Java
SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

Memodifikasi cluster.

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); } }
  • Untuk API detailnya, lihat ModifyClusterdi AWS SDK for Java 2.x APIReferensi.

JavaScript
SDKuntuk JavaScript (v3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

Buat klien.

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 };

Memodifikasi cluster.

// 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();
  • Untuk API detailnya, lihat ModifyClusterdi AWS SDK for JavaScript APIReferensi.

Kotlin
SDKuntuk Kotlin
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.

Memodifikasi cluster.

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", ) } }
Python
SDKuntuk Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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

Kode berikut membuat instance objek. RedshiftWrapper

client = boto3.client("redshift") redhift_wrapper = RedshiftWrapper(client)