Amazon Redshift non supporterà più la creazione di nuovi Python UDFs a partire dalla Patch 198. Python esistente UDFs continuerà a funzionare fino al 30 giugno 2026. Per ulteriori informazioni, consulta il post del 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à.
Utilizzo DescribeClusters con un AWS SDK o una CLI
Gli esempi di codice seguenti mostrano come utilizzare DescribeClusters.
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'è altro da fare. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS
. /// <summary> /// Describe Amazon Redshift clusters. /// </summary> /// <param name="clusterIdentifier">Optional cluster identifier to describe a specific cluster.</param> /// <returns>A list of clusters.</returns> public async Task<List<Cluster>> DescribeClustersAsync(string? clusterIdentifier = null) { try { var clusters = new List<Cluster>(); var request = new DescribeClustersRequest(); if (!string.IsNullOrEmpty(clusterIdentifier)) { request.ClusterIdentifier = clusterIdentifier; } var clustersPaginator = _redshiftClient.Paginators.DescribeClusters(request); await foreach (var response in clustersPaginator.Responses) { if (response.Clusters != null) clusters.AddRange(response.Clusters); } Console.WriteLine($"{clusters.Count} cluster(s) retrieved."); foreach (var cluster in clusters) { Console.WriteLine($"\t{cluster.ClusterIdentifier} (Status: {cluster.ClusterStatus})"); } return clusters; } catch (ClusterNotFoundException ex) { Console.WriteLine($"Cluster {clusterIdentifier} not found: {ex.Message}"); throw; } catch (Exception ex) { Console.WriteLine($"Couldn't describe clusters. Here's why: {ex.Message}"); throw; } }-
Per i dettagli sull'API, consulta la DescribeClusterssezione AWS SDK per .NET API Reference.
-
- CLI
-
- AWS CLI
-
L' ClustersThis esempio Get a Description of All restituisce una descrizione di tutti i cluster dell'account. Per impostazione predefinita, l’output è in formato JSON. Comando:
aws redshift describe-clustersRisultato:
{ "Clusters": [ { "NodeType": "dw.hs1.xlarge", "Endpoint": { "Port": 5439, "Address": "mycluster.coqoarplqhsn.us-east-1.redshift.amazonaws.com" }, "ClusterVersion": "1.0", "PubliclyAccessible": "true", "MasterUsername": "adminuser", "ClusterParameterGroups": [ { "ParameterApplyStatus": "in-sync", "ParameterGroupName": "default.redshift-1.0" } ], "ClusterSecurityGroups": [ { "Status": "active", "ClusterSecurityGroupName": "default" } ], "AllowVersionUpgrade": true, "VpcSecurityGroups": \[], "AvailabilityZone": "us-east-1a", "ClusterCreateTime": "2013-01-22T21:59:29.559Z", "PreferredMaintenanceWindow": "sat:03:30-sat:04:00", "AutomatedSnapshotRetentionPeriod": 1, "ClusterStatus": "available", "ClusterIdentifier": "mycluster", "DBName": "dev", "NumberOfNodes": 2, "PendingModifiedValues": {} } ], "ResponseMetadata": { "RequestId": "65b71cac-64df-11e2-8f5b-e90bd6c77476" } }È inoltre possibile ottenere le stesse informazioni in formato testo utilizzando l’opzione
--output text. Comando:Opzione
--output text. Comando:Opzione. Comando:
aws redshift describe-clusters --output textRisultato:
dw.hs1.xlarge 1.0 true adminuser True us-east-1a 2013-01-22T21:59:29.559Z sat:03:30-sat:04:00 1 available mycluster dev 2 ENDPOINT 5439 mycluster.coqoarplqhsn.us-east-1.redshift.amazonaws.com in-sync default.redshift-1.0 active default PENDINGMODIFIEDVALUES RESPONSEMETADATA 934281a8-64df-11e2-b07c-f7fbdd006c67-
Per i dettagli sull'API, consulta DescribeClusters AWS CLI
Command Reference.
-
- Go
-
- SDK per Go V2
-
Nota
C'è altro 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 } // DescribeClusters returns information about the given cluster. func (actor RedshiftActions) DescribeClusters(ctx context.Context, clusterId string) (*redshift.DescribeClustersOutput, error) { input, err := actor.RedshiftClient.DescribeClusters(ctx, &redshift.DescribeClustersInput{ ClusterIdentifier: aws.String(clusterId), }) var opErr *types.AccessToClusterDeniedFault if errors.As(err, &opErr) { println("Access to cluster denied.") panic(err) } else if err != nil { println("Failed to describe Redshift clusters.") return nil, err } return input, nil }-
Per i dettagli sull'API, consulta la DescribeClusters
sezione AWS SDK per Go API Reference.
-
- Java
-
- SDK per Java 2.x
-
Nota
C'è altro su GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS
. Descrive il cluster.
/** * Waits asynchronously for the specified cluster to become available. * @param clusterId the identifier of the cluster to wait for * @return a {@link CompletableFuture} that completes when the cluster is ready */ public CompletableFuture<Void> waitForClusterReadyAsync(String clusterId) { DescribeClustersRequest clustersRequest = DescribeClustersRequest.builder() .clusterIdentifier(clusterId) .build(); logger.info("Waiting for cluster to become available. This may take a few minutes."); long startTime = System.currentTimeMillis(); // Recursive method to poll the cluster status. return checkClusterStatusAsync(clustersRequest, startTime); } private CompletableFuture<Void> checkClusterStatusAsync(DescribeClustersRequest clustersRequest, long startTime) { return getAsyncClient().describeClusters(clustersRequest) .thenCompose(clusterResponse -> { List<Cluster> clusterList = clusterResponse.clusters(); boolean clusterReady = false; for (Cluster cluster : clusterList) { if ("available".equals(cluster.clusterStatus())) { clusterReady = true; break; } } if (clusterReady) { logger.info(String.format("Cluster is available!")); return CompletableFuture.completedFuture(null); } else { long elapsedTimeMillis = System.currentTimeMillis() - startTime; long elapsedSeconds = elapsedTimeMillis / 1000; long minutes = elapsedSeconds / 60; long seconds = elapsedSeconds % 60; System.out.printf("\rElapsed Time: %02d:%02d - Waiting for cluster...", minutes, seconds); System.out.flush(); // Wait 1 second before the next status check return CompletableFuture.runAsync(() -> { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { throw new RuntimeException("Error during sleep: " + e.getMessage(), e); } }).thenCompose(ignored -> checkClusterStatusAsync(clustersRequest, startTime)); } }).exceptionally(exception -> { throw new RuntimeException("Failed to get cluster status: " + exception.getMessage(), exception); }); }-
Per i dettagli sull'API, consulta la DescribeClusterssezione AWS SDK for Java 2.x API Reference.
-
- JavaScript
-
- SDK per JavaScript (v3)
-
Nota
C'è altro da fare. 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 };Descrive i cluster.
// Import required AWS SDK clients and commands for Node.js import { DescribeClustersCommand } from "@aws-sdk/client-redshift"; import { redshiftClient } from "./libs/redshiftClient.js"; const params = { ClusterIdentifier: "CLUSTER_NAME", }; const run = async () => { try { const data = await redshiftClient.send(new DescribeClustersCommand(params)); console.log("Success", data); return data; // For unit tests. } catch (err) { console.log("Error", err); } }; run();-
Per i dettagli sull'API, consulta la DescribeClusterssezione AWS SDK for JavaScript API Reference.
-
- Kotlin
-
- SDK per Kotlin
-
Nota
C'è altro su GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS
. Descrive il cluster.
suspend fun describeRedshiftClusters() { RedshiftClient.fromEnvironment { region = "us-west-2" }.use { redshiftClient -> val clusterResponse = redshiftClient.describeClusters(DescribeClustersRequest {}) val clusterList = clusterResponse.clusters if (clusterList != null) { for (cluster in clusterList) { println("Cluster database name is ${cluster.dbName}") println("Cluster status is ${cluster.clusterStatus}") } } } }-
Per i dettagli sull'API, DescribeClusters
consulta AWS SDK for Kotlin API reference.
-
- 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 describe_clusters(self, cluster_identifier): """ Describes a cluster. :param cluster_identifier: The cluster identifier. :return: A list of clusters. """ try: kwargs = {} if cluster_identifier: kwargs["ClusterIdentifier"] = cluster_identifier paginator = self.client.get_paginator("describe_clusters") clusters = [] for page in paginator.paginate(**kwargs): clusters.extend(page["Clusters"]) return clusters except ClientError as err: logging.error( "Couldn't describe a cluster. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raiseIl codice seguente crea un'istanza dell' RedshiftWrapper oggetto.
client = boto3.client("redshift") redhift_wrapper = RedshiftWrapper(client)-
Per i dettagli sull'API, consulta DescribeClusters AWSSDK for Python (Boto3) API Reference.
-
- SAP ABAP
-
- SDK per SAP ABAP
-
Nota
C'è altro da fare. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS
. Descrive il cluster.
TRY. " Example values: iv_cluster_identifier = 'my-redshift-cluster' (optional) oo_result = lo_rsh->describeclusters( iv_clusteridentifier = iv_cluster_identifier ). lt_clusters = oo_result->get_clusters( ). lv_cluster_count = lines( lt_clusters ). MESSAGE |Retrieved { lv_cluster_count } cluster(s).| TYPE 'I'. CATCH /aws1/cx_rshclustnotfoundfault. MESSAGE 'Cluster not found.' TYPE 'I'. ENDTRY.-
Per i dettagli sulle API, DescribeClustersconsulta AWS SDK for SAP ABAP API reference.
-
Per un elenco completo delle guide per sviluppatori AWS SDK e degli esempi di codice, consulta. Utilizzo del servizio con un SDK AWS Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell’SDK.