または CreateClusterAWS SDKで を使用する CLI - AWS SDK コード例

AWS Doc SDK Examples GitHub リポジトリには他にも AWS SDK例があります。

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

または CreateClusterAWS SDKで を使用する CLI

以下のコード例は、CreateCluster の使用方法を示しています。

CLI
AWS CLI

最小限のクラスターを作成する ParametersThis の例は、最小限のパラメータセットでクラスターを作成します。デフォルトでは、出力は JSON format.Command です。

aws redshift create-cluster --node-type dw.hs1.xlarge --number-of-nodes 2 --master-username adminuser --master-user-password TopSecret1 --cluster-identifier mycluster

結果:

{ "Cluster": { "NodeType": "dw.hs1.xlarge", "ClusterVersion": "1.0", "PubliclyAccessible": "true", "MasterUsername": "adminuser", "ClusterParameterGroups": [ { "ParameterApplyStatus": "in-sync", "ParameterGroupName": "default.redshift-1.0" } ], "ClusterSecurityGroups": [ { "Status": "active", "ClusterSecurityGroupName": "default" } ], "AllowVersionUpgrade": true, "VpcSecurityGroups": \[], "PreferredMaintenanceWindow": "sat:03:30-sat:04:00", "AutomatedSnapshotRetentionPeriod": 1, "ClusterStatus": "creating", "ClusterIdentifier": "mycluster", "DBName": "dev", "NumberOfNodes": 2, "PendingModifiedValues": { "MasterUserPassword": "\****" } }, "ResponseMetadata": { "RequestId": "7cf4bcfc-64dd-11e2-bea9-49e0ce183f07" } }
  • API 詳細については、「 コマンドリファレンスCreateCluster」の「」を参照してください。 AWS CLI

Java
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) .masterUserPassword(masterUserPassword) .nodeType("ra3.4xlarge") .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 詳細については、「 リファレンスCreateCluster」の「」を参照してください。 AWS SDK for Java 2.x API

JavaScript
SDK の JavaScript (v3)
注記

については、「」を参照してください 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 { CreateClusterCommand } from "@aws-sdk/client-redshift"; import { redshiftClient } from "./libs/redshiftClient.js"; const params = { ClusterIdentifier: "CLUSTER_NAME", // Required NodeType: "NODE_TYPE", //Required MasterUsername: "MASTER_USER_NAME", // Required - must be lowercase MasterUserPassword: "MASTER_USER_PASSWORD", // Required - must contain at least one uppercase letter, and one number ClusterType: "CLUSTER_TYPE", // Required IAMRoleARN: "IAM_ROLE_ARN", // Optional - the ARN of an IAM role with permissions your cluster needs to access other AWS services on your behalf, such as Amazon S3. ClusterSubnetGroupName: "CLUSTER_SUBNET_GROUPNAME", //Optional - the name of a cluster subnet group to be associated with this cluster. Defaults to 'default' if not specified. DBName: "DATABASE_NAME", // Optional - defaults to 'dev' if not specified Port: "PORT_NUMBER", // Optional - defaults to '5439' if not specified }; const run = async () => { try { const data = await redshiftClient.send(new CreateClusterCommand(params)); console.log( "Cluster " + data.Cluster.ClusterIdentifier + " successfully created", ); return data; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
  • API 詳細については、「 リファレンスCreateCluster」の「」を参照してください。 AWS SDK for JavaScript API

Kotlin
SDK Kotlin 用
注記

については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

クラスターを作成する。

suspend fun createCluster( clusterId: String?, masterUsernameVal: String?, masterUserPasswordVal: String?, ) { val clusterRequest = CreateClusterRequest { clusterIdentifier = clusterId masterUsername = masterUsernameVal masterUserPassword = masterUserPasswordVal nodeType = "ra3.4xlarge" publiclyAccessible = true numberOfNodes = 2 } RedshiftClient { region = "us-east-1" }.use { redshiftClient -> val clusterResponse = redshiftClient.createCluster(clusterRequest) println("Created cluster ${clusterResponse.cluster?.clusterIdentifier}") } }
  • API 詳細については、Kotlin リファレンス CreateClusterの「」の「」を参照してください。 AWS SDK API

Python
SDK for Python (Boto3)
注記

については、「」を参照してください 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 create_cluster( self, cluster_identifier, node_type, master_username, master_user_password, publicly_accessible, number_of_nodes, ): """ Creates a cluster. :param cluster_identifier: The name of the cluster. :param node_type: The type of node in the cluster. :param master_username: The master username. :param master_user_password: The master user password. :param publicly_accessible: Whether the cluster is publicly accessible. :param number_of_nodes: The number of nodes in the cluster. :return: The cluster. """ try: cluster = self.client.create_cluster( ClusterIdentifier=cluster_identifier, NodeType=node_type, MasterUsername=master_username, MasterUserPassword=master_user_password, PubliclyAccessible=publicly_accessible, NumberOfNodes=number_of_nodes, ) return cluster except ClientError as err: logging.error( "Couldn't create 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 詳細については、「 for Python (Boto3) リファレンスCreateCluster」の「」を参照してください。 AWS SDK API