搭DeleteCluster配 AWS SDK或使用 CLI - AWS SDK 程式碼範例

AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DeleteCluster配 AWS SDK或使用 CLI

下列程式碼範例會示範如何使用DeleteCluster

CLI
AWS CLI

刪除沒有最終叢集的叢集 SnapshotThis 範例會刪除叢集,強制刪除資料,因此不會建立最終叢集快照。命令:

aws redshift delete-cluster --cluster-identifier mycluster --skip-final-cluster-snapshot

刪除叢集,允許最終叢集 SnapshotThis 範例刪除叢集,但指定最終的叢集快照。命令:

aws redshift delete-cluster --cluster-identifier mycluster --final-cluster-snapshot-identifier myfinalsnapshot
  • 如需詳API細資訊,請參閱AWS CLI 指令參考DeleteCluster中的。

Java
SDK對於爪哇 2.x
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

刪除叢集。

public static void deleteRedshiftCluster(RedshiftClient redshiftClient, String clusterId) { try { DeleteClusterRequest deleteClusterRequest = DeleteClusterRequest.builder() .clusterIdentifier(clusterId) .skipFinalClusterSnapshot(true) .build(); DeleteClusterResponse response = redshiftClient.deleteCluster(deleteClusterRequest); System.out.println("The status is " + response.cluster().clusterStatus()); } catch (RedshiftException e) { System.err.println(e.getMessage()); System.exit(1); } }
  • 如需詳API細資訊,請參閱AWS SDK for Java 2.x API參考DeleteCluster中的。

JavaScript
SDK對於 JavaScript (3)
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

建立用戶端。

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 { 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();
  • 如需詳API細資訊,請參閱AWS SDK for JavaScript API參考DeleteCluster中的。

Kotlin
SDK對於科特林
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

刪除叢集。

suspend fun deleteRedshiftCluster(clusterId: String?) { val request = DeleteClusterRequest { clusterIdentifier = clusterId skipFinalClusterSnapshot = true } RedshiftClient { region = "us-west-2" }.use { redshiftClient -> val response = redshiftClient.deleteCluster(request) println("The status is ${response.cluster?.clusterStatus}") } }
  • 有API關詳細資訊,請參閱DeleteClusterAWS SDK的以取得 Kotlin API 的參考資料

Python
SDK對於 Python(肉毒桿菌 3)
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 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"], ) raise

下面的代碼實例化對 RedshiftWrapper 象。

client = boto3.client("redshift") redhift_wrapper = RedshiftWrapper(client)
  • 如需詳API細資訊,請參閱DeleteClusterAWS SDK的〈〉以取得 Python (Boto3) API 參考資料。