Amazon Redshift non supporterà più l'uso delle UDF Python dopo il 30 giugno 2026. Inizieremo ad applicarlo gradualmente. Per ulteriori informazioni sui dettagli della fine del ciclo di vita e sulle opzioni di migrazione di Python, consulta la post sul blog
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Usare DeleteCluster con un AWS SDK o CLI
I seguenti esempi di codice mostrano come usare DeleteCluster.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:
- .NET
-
- SDK per .NET (v4)
-
Nota
C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS
. /// <summary> /// Delete an Amazon Redshift cluster without a final snapshot. /// </summary> /// <param name="clusterIdentifier">The identifier for the cluster.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteClusterWithoutSnapshotAsync(string clusterIdentifier) { try { var request = new DeleteClusterRequest { ClusterIdentifier = clusterIdentifier, SkipFinalClusterSnapshot = true }; var response = await _redshiftClient.DeleteClusterAsync(request); Console.WriteLine($"The {clusterIdentifier} was deleted"); return true; } catch (ClusterNotFoundException ex) { Console.WriteLine($"Cluster not found: {ex.Message}"); return false; } catch (Exception ex) { Console.WriteLine($"Couldn't delete cluster. Here's why: {ex.Message}"); return false; } }-
Per i dettagli sull'API, vedi DeleteCluster nel AWS SDK per .NET Riferimento API.
-
- CLI
-
- AWS CLI
-
Esempio 1: eliminare un cluster senza un'istantanea finale del cluster
Quanto segue
delete-clusterL'esempio elimina un cluster, forzando l'eliminazione dei dati in modo che non venga creata alcuna istantanea finale del cluster.aws redshift delete-cluster \ --cluster-identifiermycluster\ --skip-final-cluster-snapshotOutput:
{ "Cluster": { "ClusterIdentifier": "mycluster", "NodeType": "dc2.large", "ClusterStatus": "deleting", "ClusterAvailabilityStatus": "Modifying", "MasterUsername": "adminuser", "DBName": "dev", "Endpoint": { "Address": "mycluster.c1a2b3c4d5e6.us-west-2.redshift.amazonaws.com", "Port": 5439 }, "ClusterCreateTime": "2019-12-23T21:42:51.430Z", "AutomatedSnapshotRetentionPeriod": 1, "ManualSnapshotRetentionPeriod": -1, "ClusterSecurityGroups": [], "VpcSecurityGroups": [ { "VpcSecurityGroupId": "sg-0a1b2c3d4e5f6a7b8", "Status": "active" } ], "ClusterParameterGroups": [ { "ParameterGroupName": "default.redshift-1.0", "ParameterApplyStatus": "in-sync" } ], "ClusterSubnetGroupName": "default", "VpcId": "vpc-0a1b2c3d4e5f6a7b8", "AvailabilityZone": "us-west-2a", "PreferredMaintenanceWindow": "sat:03:30-sat:04:00", "PendingModifiedValues": {}, "ClusterVersion": "1.0", "AllowVersionUpgrade": true, "NumberOfNodes": 2, "PubliclyAccessible": false, "Encrypted": false, "Tags": [], "EnhancedVpcRouting": false, "IamRoles": [], "MaintenanceTrackName": "current", "DeferredMaintenanceWindows": [], "NextMaintenanceWindowStartTime": "2019-12-28T03:30:00Z" } }Per ulteriori informazioni, vedere Chiusura ed eliminazione di un cluster nel Guida alla gestione di Amazon Redshift.
Esempio 2: eliminare un cluster, consentire un'istantanea finale del cluster
Quanto segue
delete-clusterL'esempio elimina un cluster, ma specifica un'istantanea finale del cluster.aws redshift delete-cluster \ --cluster-identifiermycluster\ --final-cluster-snapshot-identifiermyfinalsnapshotOutput:
{ "Cluster": { "ClusterIdentifier": "mycluster", "NodeType": "dc2.large", "ClusterStatus": "deleting", "ClusterAvailabilityStatus": "Modifying", "MasterUsername": "adminuser", "DBName": "dev", "Endpoint": { "Address": "mycluster.c1a2b3c4d5e6.us-west-2.redshift.amazonaws.com", "Port": 5439 }, "ClusterCreateTime": "2019-12-23T21:42:51.430Z", "AutomatedSnapshotRetentionPeriod": 1, "ManualSnapshotRetentionPeriod": -1, "ClusterSecurityGroups": [], "VpcSecurityGroups": [ { "VpcSecurityGroupId": "sg-0a1b2c3d4e5f6a7b8", "Status": "active" } ], "ClusterParameterGroups": [ { "ParameterGroupName": "default.redshift-1.0", "ParameterApplyStatus": "in-sync" } ], "ClusterSubnetGroupName": "default", "VpcId": "vpc-0a1b2c3d4e5f6a7b8", "AvailabilityZone": "us-west-2a", "PreferredMaintenanceWindow": "sat:03:30-sat:04:00", "PendingModifiedValues": {}, "ClusterVersion": "1.0", "AllowVersionUpgrade": true, "NumberOfNodes": 2, "PubliclyAccessible": false, "Encrypted": false, "Tags": [], "EnhancedVpcRouting": false, "IamRoles": [], "MaintenanceTrackName": "current", "DeferredMaintenanceWindows": [], "NextMaintenanceWindowStartTime": "2019-12-28T03:30:00Z" } }Per ulteriori informazioni, vedere Chiusura ed eliminazione di un cluster nel Guida alla gestione di Amazon Redshift.
-
Per i dettagli sull'API, vedi DeleteCluster
nel AWS CLI Riferimento al comando.
-
- Go
-
- SDK per Go V2
-
Nota
C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice 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 } // DeleteCluster deletes the given cluster. func (actor RedshiftActions) DeleteCluster(ctx context.Context, clusterId string) (bool, error) { input := redshift.DeleteClusterInput{ ClusterIdentifier: aws.String(clusterId), SkipFinalClusterSnapshot: aws.Bool(true), } _, err := actor.RedshiftClient.DeleteCluster(ctx, &input) var opErr *types.ClusterNotFoundFault if err != nil && errors.As(err, &opErr) { log.Println("Cluster was not found. Where could it be?") return false, err } else if err != nil { log.Printf("Failed to delete Redshift cluster: %v\n", err) return false, err } waiter := redshift.NewClusterDeletedWaiter(actor.RedshiftClient) err = waiter.Wait(ctx, &redshift.DescribeClustersInput{ ClusterIdentifier: aws.String(clusterId), }, 5*time.Minute) if err != nil { log.Printf("Wait time exceeded for deleting cluster, continuing: %v\n", err) } log.Printf("The cluster %s was deleted\n", clusterId) return true, nil }-
Per i dettagli sull'API, vedi DeleteCluster
nel AWS SDK per Go Riferimento API.
-
- Java
-
- SDK per Java 2.x
-
Nota
C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS
. Elimina il cluster.
/** * Deletes a Redshift cluster asynchronously. * * @param clusterId the identifier of the Redshift cluster to be deleted * @return a {@link CompletableFuture} that represents the asynchronous operation of deleting the Redshift cluster */ public CompletableFuture<DeleteClusterResponse> deleteRedshiftClusterAsync(String clusterId) { DeleteClusterRequest deleteClusterRequest = DeleteClusterRequest.builder() .clusterIdentifier(clusterId) .skipFinalClusterSnapshot(true) .build(); return getAsyncClient().deleteCluster(deleteClusterRequest) .whenComplete((response, exception) -> { if (exception != null) { // Handle exceptions if (exception.getCause() instanceof RedshiftException) { logger.info("Error: {}", exception.getMessage()); } else { logger.info("Unexpected error: {}", exception.getMessage()); } } else { // Handle successful response logger.info("The status is {}", response.cluster().clusterStatus()); } }); }-
Per i dettagli sull'API, vedi DeleteCluster nel AWS SDK for Java 2.x Riferimento API.
-
- JavaScript
-
- SDK per JavaScript (v3)
-
Nota
C'è dell'altro GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS
. Crea il client.
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 };Crea il cluster.
// Import required AWS SDK clients and commands for Node.js import { DeleteClusterCommand } from "@aws-sdk/client-redshift"; import { redshiftClient } from "./libs/redshiftClient.js"; const params = { ClusterIdentifier: "CLUSTER_NAME", SkipFinalClusterSnapshot: false, FinalClusterSnapshotIdentifier: "CLUSTER_SNAPSHOT_ID", }; const run = async () => { try { const data = await redshiftClient.send(new DeleteClusterCommand(params)); console.log("Success, cluster deleted. ", data); return data; // For unit tests. } catch (err) { console.log("Error", err); } }; run();-
Per i dettagli sull'API, vedi DeleteCluster nel AWS SDK per JavaScript Riferimento API.
-
- Kotlin
-
- SDK per Kotlin
-
Nota
C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS
. Elimina il cluster.
suspend fun deleteRedshiftCluster(clusterId: String?) { val request = DeleteClusterRequest { clusterIdentifier = clusterId skipFinalClusterSnapshot = true } RedshiftClient.fromEnvironment { region = "us-west-2" }.use { redshiftClient -> val response = redshiftClient.deleteCluster(request) println("The status is ${response.cluster?.clusterStatus}") } }-
Per i dettagli sull'API, vedi DeleteCluster
nel AWS Riferimento all'API SDK per Kotlin.
-
- Python
-
- SDK per Python (Boto3)
-
Nota
C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice 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 delete_cluster(self, cluster_identifier): """ Deletes a cluster. :param cluster_identifier: The cluster identifier. """ try: self.client.delete_cluster( ClusterIdentifier=cluster_identifier, SkipFinalClusterSnapshot=True ) except ClientError as err: logging.error( "Couldn't delete a cluster. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raiseIl codice seguente crea un'istanza di RedshiftWrapper oggetto.
client = boto3.client("redshift") redhift_wrapper = RedshiftWrapper(client)-
Per i dettagli sull'API, vedi DeleteCluster nel AWS Riferimento alle API SDK per Python (Boto3).
-
- SAP ABAP
-
- SDK per SAP ABAP
-
Nota
C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS
. Elimina il cluster.
TRY. " Example values: iv_cluster_identifier = 'my-redshift-cluster' lo_rsh->deletecluster( iv_clusteridentifier = iv_cluster_identifier iv_skipfinalclustersnapshot = abap_true ). MESSAGE 'Redshift cluster deleted successfully.' TYPE 'I'. CATCH /aws1/cx_rshclustnotfoundfault. MESSAGE 'Cluster not found.' TYPE 'I'. CATCH /aws1/cx_rshinvcluststatefault. MESSAGE 'Invalid cluster state for deletion.' TYPE 'I'. ENDTRY.-
Per i dettagli sull'API, vedi DeleteCluster nel AWS Riferimento all'API SDK per SAP ABAP.
-
Per un elenco completo di AWS Guide per sviluppatori SDK ed esempi di codice, consulta Utilizzo di questo servizio con un AWS SDK. Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell’SDK.