Java 2.x 用 SDK を使用した Amazon Redshift の例 - AWSSDK コードサンプル

AWSDocAWS SDKGitHub サンプルリポジトリには、さらに多くの SDK サンプルがあります

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Java 2.x 用 SDK を使用した Amazon Redshift の例

次のコード例は、を使用して Amazon Redshift ft ででで一般的なシナリオを実装してAmazon Redshift でで一般的なシナリオを実装して一般的なシナリオを実装して Amazon RedhiftAWS SDK for Java 2.x でで一般的なシナリオを実装して Amazon R

アクション」は、個々のサービス関数の呼び出し方法を示すコードの抜粋です。

シナリオ」は、同じサービス内で複数の関数を呼び出して、特定のタスクを実行する方法を示すコード例です。

それぞれの例にはGitHub、へのリンクがあり、コンテキストでコードを設定および実行する方法についての説明が記載されています。

トピック

アクション

次のコード例は、Amazon Redshift クラスターを作成する方法を示しています。

SDK for Java 2.x
注記

他にもありますGitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

クラスターを作成します。

public static void createCluster(RedshiftClient redshiftClient, String clusterId, String masterUsername, String masterUserPassword ) { try { CreateClusterRequest clusterRequest = CreateClusterRequest.builder() .clusterIdentifier(clusterId) .masterUsername(masterUsername) // set the user name here .masterUserPassword(masterUserPassword) // set the user password here .nodeType("ds2.xlarge") .publiclyAccessible(true) .numberOfNodes(2) .build(); CreateClusterResponse clusterResponse = redshiftClient.createCluster(clusterRequest); System.out.println("Created cluster " + clusterResponse.cluster().clusterIdentifier()); } catch (RedshiftException e) { System.err.println(e.getMessage()); System.exit(1); } }
  • API の詳細については、AWS SDK for Java 2.xAPI CreateClusterリファレンスのを参照してください

次のコード例は、Amazon Redshift クラスターを削除する方法を示しています。

SDK for Java 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.xAPI DeleteClusterリファレンスのを参照してください

次のコード例は、Amazon Redshift クラスターの記述方法を示しています。

SDK for Java 2.x
注記

他にもありますGitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

クラスターを説明してください。

public static void describeRedshiftClusters(RedshiftClient redshiftClient) { try { DescribeClustersResponse clusterResponse = redshiftClient.describeClusters(); List<Cluster> clusterList = clusterResponse.clusters(); for (Cluster cluster: clusterList) { System.out.println("Cluster database name is: "+cluster.dbName()); System.out.println("Cluster status is: "+cluster.clusterStatus()); } } catch (RedshiftException e) { System.err.println(e.getMessage()); System.exit(1); } }
  • API の詳細については、AWS SDK for Java 2.xAPI DescribeClustersリファレンスのを参照してください

次のコード例は、Amazon Redshift クラスターを変更する方法を示しています。

SDK for Java 2.x
注記

他にもありますGitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

クラスターを変更します。

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); } }
  • API の詳細については、AWS SDK for Java 2.xAPI ModifyClusterリファレンスのを参照してください