Amazon Redshift tidak akan lagi mendukung penggunaan Python UDF setelah 30 Juni 2026. Kami akan mulai menegakkannya secara bertahap. Untuk informasi lebih lanjut tentang detail opsi akhir masa pakai dan migrasi Python, lihat posting blog
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 menggunakan ModifyCluster.
Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:
- .NET
-
- SDK untuk .NET (v4)
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS
. /// <summary> /// Modify an Amazon Redshift cluster. /// </summary> /// <param name="clusterIdentifier">The identifier for the cluster.</param> /// <param name="preferredMaintenanceWindow">The preferred maintenance window.</param> /// <returns>True if successful.</returns> public async Task<bool> ModifyClusterAsync(string clusterIdentifier, string preferredMaintenanceWindow) { try { var request = new ModifyClusterRequest { ClusterIdentifier = clusterIdentifier, PreferredMaintenanceWindow = preferredMaintenanceWindow }; var response = await _redshiftClient.ModifyClusterAsync(request); Console.WriteLine($"The modified cluster was successfully modified and has {response.Cluster.PreferredMaintenanceWindow} as the maintenance window"); return true; } catch (ClusterNotFoundException ex) { Console.WriteLine($"Cluster {clusterIdentifier} not found: {ex.Message}"); return false; } catch (Exception ex) { Console.WriteLine($"Couldn't modify cluster. Here's why: {ex.Message}"); return false; } }-
Untuk detail API, lihat ModifyCluster di AWS SDK untuk .NET Referensi API.
-
- CLI
-
- AWS CLI
-
Contoh 1: Untuk mengaitkan grup keamanan dengan cluster
Berikut ini
modify-clustercontoh mengaitkan grup keamanan cluster dengan cluster yang ditentukan.aws redshift modify-cluster \ --cluster-identifiermycluster\ --cluster-security-groupsmysecuritygroupOutput:
{ "Cluster": { "ClusterIdentifier": "mycluster", "NodeType": "dc2.large", "ClusterStatus": "available", "ClusterAvailabilityStatus": "Available", "MasterUsername": "adminuser", "DBName": "dev", "Endpoint": { "Address": "mycluster.cmeaswqeuae.us-west-2.redshift.amazonaws.com", "Port": 5439 }, "ClusterCreateTime": "2019-12-02T22:45:07.890Z", "AutomatedSnapshotRetentionPeriod": 1, "ManualSnapshotRetentionPeriod": -1, "ClusterSecurityGroups": [ { "ClusterSecurityGroupName": "default", "Status": "removing" }, { "ClusterSecurityGroupName": "mysecuritygroup", "Status": "adding" } ], "VpcSecurityGroups": [], "ClusterParameterGroups": [ { "ParameterGroupName": "default.redshift-1.0", "ParameterApplyStatus": "in-sync" } ], "AvailabilityZone": "us-west-2a", "PreferredMaintenanceWindow": "sat:03:30-sat:04:00", "PendingModifiedValues": {}, "ClusterVersion": "1.0", "AllowVersionUpgrade": true, "NumberOfNodes": 2, "PubliclyAccessible": true, "Encrypted": false, "Tags": [], "EnhancedVpcRouting": false, "IamRoles": [], "MaintenanceTrackName": "current" } }Untuk informasi lebih lanjut, lihat Memodifikasi cluster di Panduan Manajemen Amazon Redshift.
Contoh 2: Untuk memodifikasi jendela pemeliharaan untuk cluster
Berikut ini
modify-clustercontoh mengubah jendela pemeliharaan mingguan yang disukai untuk cluster menjadi jendela minimum empat jam mulai hari Minggu pukul 11:15 malam, dan berakhir Senin pukul 3:15.aws redshift modify-cluster \ --cluster-identifiermycluster\ --preferred-maintenance-windowSun:23:15-Mon:03:15Output:
{ "Cluster": { "ClusterIdentifier": "mycluster", "NodeType": "dc2.large", "ClusterStatus": "available", "ClusterAvailabilityStatus": "Available", "MasterUsername": "adminuser", "DBName": "dev", "Endpoint": { "Address": "mycluster.cmeaswqeuae.us-west-2.redshift.amazonaws.com", "Port": 5439 }, "ClusterCreateTime": "2019-12-02T22:45:07.890Z", "AutomatedSnapshotRetentionPeriod": 1, "ManualSnapshotRetentionPeriod": -1, "ClusterSecurityGroups": [ { "ClusterSecurityGroupName": "default", "Status": "active" } ], "VpcSecurityGroups": [], "ClusterParameterGroups": [ { "ParameterGroupName": "default.redshift-1.0", "ParameterApplyStatus": "in-sync" } ], "AvailabilityZone": "us-west-2a", "PreferredMaintenanceWindow": "sun:23:15-mon:03:15", "PendingModifiedValues": {}, "ClusterVersion": "1.0", "AllowVersionUpgrade": true, "NumberOfNodes": 2, "PubliclyAccessible": true, "Encrypted": false, "Tags": [], "EnhancedVpcRouting": false, "IamRoles": [], "MaintenanceTrackName": "current" } }Untuk informasi lebih lanjut, lihat Jendela pemeliharaan di Panduan Manajemen Amazon Redshift.
Contoh 3: Untuk mengubah kata sandi master untuk cluster
Berikut ini
modify-clustercontoh mengubah kata sandi utama untuk cluster.aws redshift modify-cluster \ --cluster-identifiermycluster\ --master-user-passwordA1b2c3d4Output:
{ "Cluster": { "ClusterIdentifier": "mycluster", "NodeType": "dc2.large", "ClusterStatus": "available", "ClusterAvailabilityStatus": "Available", "MasterUsername": "adminuser", "DBName": "dev", "Endpoint": { "Address": "mycluster.cmeaswqeuae.us-west-2.redshift.amazonaws.com", "Port": 5439 }, "ClusterCreateTime": "2019-12-02T22:45:07.890Z", "AutomatedSnapshotRetentionPeriod": 1, "ManualSnapshotRetentionPeriod": -1, "ClusterSecurityGroups": [ { "ClusterSecurityGroupName": "default", "Status": "active" } ], "VpcSecurityGroups": [], "ClusterParameterGroups": [ { "ParameterGroupName": "default.redshift-1.0", "ParameterApplyStatus": "in-sync" } ], "AvailabilityZone": "us-west-2a", "PreferredMaintenanceWindow": "sat:03:30-sat:04:00", "PendingModifiedValues": { "MasterUserPassword": "****" }, "ClusterVersion": "1.0", "AllowVersionUpgrade": true, "NumberOfNodes": 2, "PubliclyAccessible": true, "Encrypted": false, "Tags": [], "EnhancedVpcRouting": false, "IamRoles": [], "MaintenanceTrackName": "current" } }Untuk informasi lebih lanjut, lihat Memodifikasi cluster di Panduan Manajemen Amazon Redshift.
-
Untuk detail API, lihat ModifyCluster
di AWS CLI Referensi Perintah.
-
- Go
-
- SDK untuk Go V2
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS
. import ( "context" "errors" "log" "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/redshift" "github.com/aws/aws-sdk-go-v2/service/redshift/types" ) // RedshiftActions wraps Redshift service actions. type RedshiftActions struct { RedshiftClient *redshift.Client } // ModifyCluster sets the preferred maintenance window for the given cluster. func (actor RedshiftActions) ModifyCluster(ctx context.Context, clusterId string, maintenanceWindow string) *redshift.ModifyClusterOutput { // Modify the cluster's maintenance window input := &redshift.ModifyClusterInput{ ClusterIdentifier: aws.String(clusterId), PreferredMaintenanceWindow: aws.String(maintenanceWindow), } var opErr *types.InvalidClusterStateFault output, err := actor.RedshiftClient.ModifyCluster(ctx, input) if err != nil && errors.As(err, &opErr) { log.Println("Cluster is in an invalid state.") panic(err) } else if err != nil { log.Printf("Failed to modify Redshift cluster: %v\n", err) panic(err) } log.Printf("The cluster was successfully modified and now has %s as the maintenance window\n", *output.Cluster.PreferredMaintenanceWindow) return output }-
Untuk detail API, lihat ModifyCluster
di AWS SDK untuk Go Referensi API.
-
- Java
-
- SDK untuk Java 2.x
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS
. Ubah cluster.
/** * Modifies an Amazon Redshift cluster asynchronously. * * @param clusterId the identifier of the cluster to be modified * @return a {@link CompletableFuture} that completes when the cluster modification is complete */ public CompletableFuture<ModifyClusterResponse> modifyClusterAsync(String clusterId) { ModifyClusterRequest modifyClusterRequest = ModifyClusterRequest.builder() .clusterIdentifier(clusterId) .preferredMaintenanceWindow("wed:07:30-wed:08:00") .build(); return getAsyncClient().modifyCluster(modifyClusterRequest) .whenComplete((clusterResponse, exception) -> { if (exception != null) { if (exception.getCause() instanceof RedshiftException) { logger.info("Error: {} ", exception.getMessage()); } else { logger.info("Unexpected error: {} ", exception.getMessage()); } } else { logger.info("The modified cluster was successfully modified and has " + clusterResponse.cluster().preferredMaintenanceWindow() + " as the maintenance window"); } }); }-
Untuk detail API, lihat ModifyCluster di AWS SDK for Java 2.x Referensi API.
-
- JavaScript
-
- SDK untuk JavaScript (V3)
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur 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 };Ubah 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 detail API, lihat ModifyCluster di AWS SDK untuk JavaScript Referensi API.
-
- Kotlin
-
- SDK untuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS
. Ubah 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", ) } }-
Untuk detail API, lihat ModifyCluster
di AWS SDK untuk referensi API Kotlin.
-
- Python
-
- SDK untuk Python (Boto3)
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur 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"], ) raiseKode berikut membuat instance RedshiftWrapper objek.
client = boto3.client("redshift") redhift_wrapper = RedshiftWrapper(client)-
Untuk detail API, lihat ModifyCluster di AWS Referensi API SDK untuk Python (Boto3).
-
- SAP ABAP
-
- SDK for SAP ABAP
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS
. Ubah cluster.
TRY. " Example values: iv_cluster_identifier = 'my-redshift-cluster' " Example values: iv_pref_maintenance_wn = 'wed:07:30-wed:08:00' lo_rsh->modifycluster( iv_clusteridentifier = iv_cluster_identifier iv_preferredmaintenancewin00 = iv_pref_maintenance_wn ). MESSAGE 'Redshift cluster modified successfully.' TYPE 'I'. CATCH /aws1/cx_rshclustnotfoundfault. MESSAGE 'Cluster not found.' TYPE 'I'. CATCH /aws1/cx_rshinvcluststatefault. MESSAGE 'Invalid cluster state for modification.' TYPE 'I'. ENDTRY.-
Untuk detail API, lihat ModifyCluster di AWS SDK untuk referensi API SAP ABAP.
-
Untuk daftar lengkap AWS Panduan pengembang SDK dan contoh kode, lihat Menggunakan layanan ini dengan AWS SDK. Topik ini juga mencakup informasi tentang memulai dan detail tentang versi SDK sebelumnya.