-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
Copy pathcreate_cluster.cpp
97 lines (85 loc) · 3.23 KB
/
create_cluster.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#include <aws/core/Aws.h>
#include <aws/redshift/RedshiftClient.h>
#include <aws/redshift/model/CreateClusterRequest.h>
#include <aws/redshift/model/CreateClusterResult.h>
#include <iostream>
/**
* Create an Amazon Redshift cluster
*/
Aws::Redshift::Model::Cluster * CreateRedshiftCluster(
const Aws::String & dbName,
const Aws::String & clusterId,
const Aws::String & userName,
const Aws::String & userPassword,
const Aws::String & subnetGroupName,
const Aws::String & nodeType,
const int numberOfNodes,
const Aws::Vector <Aws::String> & iamRoles,
Aws::Redshift::Model::Cluster & cluster,
const int automatedSnapshotPeriod=0) // 0 = disable automated snapshots
{
Aws::Redshift::RedshiftClient redshift;
Aws::Redshift::Model::CreateClusterRequest redshift_req;
// Initialize all request parameters
redshift_req.SetDBName(dbName);
redshift_req.SetClusterIdentifier(clusterId);
redshift_req.SetMasterUsername(userName);
redshift_req.SetMasterUserPassword(userPassword);
redshift_req.SetClusterSubnetGroupName(subnetGroupName);
redshift_req.SetNodeType(nodeType);
redshift_req.SetNumberOfNodes(numberOfNodes);
redshift_req.SetIamRoles(iamRoles);
redshift_req.SetAutomatedSnapshotRetentionPeriod(automatedSnapshotPeriod);
// Create the cluster. Does not wait for creation to complete.
auto outcome = redshift.CreateCluster(redshift_req);
if (!outcome.IsSuccess())
{
std::cerr << "Error creating cluster. " <<
outcome.GetError().GetMessage() << std::endl;
return NULL;
}
auto result = outcome.GetResult();
cluster = result.GetCluster();
return &cluster;
}
/**
* Exercise CreateRedshiftCluster()
*/
int main(int argc, char **argv)
{
Aws::SDKOptions options;
Aws::InitAPI(options);
{
// Set these configuration values before running the program
Aws::String dbName = "dev";
Aws::String clusterId = "redshift-cluster-1";
Aws::String userName = "awsuser";
Aws::String userPassword = "AWSuser_01";
Aws::String subnetGroupName = "myredshiftsubnetgroup";
Aws::String nodeType = "dc2.large";
int numberOfNodes = 2;
Aws::Vector <Aws::String> iamRoles;
iamRoles.push_back("arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME");
Aws::Redshift::Model::Cluster cluster;
// Create the cluster. Function returns before the cluster is fully built.
if (!CreateRedshiftCluster(dbName, clusterId,
userName, userPassword,
subnetGroupName,
nodeType, numberOfNodes,
iamRoles,
cluster))
{
return 1;
}
// Print some information about the cluster
std::cout << "Creating cluster with ID " << cluster.GetClusterIdentifier() << "\n";
std::cout << "Cluster database name: " << cluster.GetDBName() << "\n";
std::cout << "Cluster status: " << cluster.GetClusterStatus() << std::endl;
}
Aws::ShutdownAPI(options);
return 0;
}