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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
template = {
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"DatabaseName": {
"Description": "The name of the first database to be created when the cluster is created",
"Type": "String",
"Default": "dev",
"AllowedPattern": "([a-z]|[0-9])+",
},
"ClusterType": {
"Description": "The type of cluster",
"Type": "String",
"Default": "single-node",
"AllowedValues": ["single-node", "multi-node"],
},
"NumberOfNodes": {
"Description": "The number of compute nodes in the cluster. For multi-node clusters, the NumberOfNodes parameter must be greater than 1",
"Type": "Number",
"Default": "1",
},
"NodeType": {
"Description": "The type of node to be provisioned",
"Type": "String",
"Default": "dw1.xlarge",
"AllowedValues": ["dw1.xlarge", "dw1.8xlarge", "dw2.large", "dw2.8xlarge"],
},
"MasterUsername": {
"Description": "The user name that is associated with the master user account for the cluster that is being created",
"Type": "String",
"Default": "defaultuser",
"AllowedPattern": "([a-z])([a-z]|[0-9])*",
},
"MasterUserPassword": {
"Description": "The password that is associated with the master user account for the cluster that is being created.",
"Type": "String",
"NoEcho": "true",
},
"InboundTraffic": {
"Description": "Allow inbound traffic to the cluster from this CIDR range.",
"Type": "String",
"MinLength": "9",
"MaxLength": "18",
"Default": "0.0.0.0/0",
"AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
"ConstraintDescription": "must be a valid CIDR range of the form x.x.x.x/x.",
},
"PortNumber": {
"Description": "The port number on which the cluster accepts incoming connections.",
"Type": "Number",
"Default": "5439",
},
},
"Conditions": {
"IsMultiNodeCluster": {"Fn::Equals": [{"Ref": "ClusterType"}, "multi-node"]}
},
"Resources": {
"RedshiftCluster": {
"Type": "AWS::Redshift::Cluster",
"DependsOn": "AttachGateway",
"Properties": {
"ClusterType": {"Ref": "ClusterType"},
"NumberOfNodes": {
"Fn::If": [
"IsMultiNodeCluster",
{"Ref": "NumberOfNodes"},
{"Ref": "AWS::NoValue"},
]
},
"NodeType": {"Ref": "NodeType"},
"DBName": {"Ref": "DatabaseName"},
"MasterUsername": {"Ref": "MasterUsername"},
"MasterUserPassword": {"Ref": "MasterUserPassword"},
"ClusterParameterGroupName": {"Ref": "RedshiftClusterParameterGroup"},
"VpcSecurityGroupIds": [{"Ref": "SecurityGroup"}],
"ClusterSubnetGroupName": {"Ref": "RedshiftClusterSubnetGroup"},
"PubliclyAccessible": "true",
"Port": {"Ref": "PortNumber"},
},
},
"RedshiftClusterParameterGroup": {
"Type": "AWS::Redshift::ClusterParameterGroup",
"Properties": {
"Description": "Cluster parameter group",
"ParameterGroupFamily": "redshift-1.0",
"Parameters": [
{
"ParameterName": "enable_user_activity_logging",
"ParameterValue": "true",
}
],
},
},
"RedshiftClusterSubnetGroup": {
"Type": "AWS::Redshift::ClusterSubnetGroup",
"Properties": {
"Description": "Cluster subnet group",
"SubnetIds": [{"Ref": "PublicSubnet"}],
},
},
"VPC": {"Type": "AWS::EC2::VPC", "Properties": {"CidrBlock": "10.0.0.0/16"}},
"PublicSubnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {"CidrBlock": "10.0.0.0/24", "VpcId": {"Ref": "VPC"}},
},
"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Security group",
"SecurityGroupIngress": [
{
"CidrIp": {"Ref": "InboundTraffic"},
"FromPort": {"Ref": "PortNumber"},
"ToPort": {"Ref": "PortNumber"},
"IpProtocol": "tcp",
}
],
"VpcId": {"Ref": "VPC"},
},
},
"myInternetGateway": {"Type": "AWS::EC2::InternetGateway"},
"AttachGateway": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"VpcId": {"Ref": "VPC"},
"InternetGatewayId": {"Ref": "myInternetGateway"},
},
},
"PublicRouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {"VpcId": {"Ref": "VPC"}},
},
"PublicRoute": {
"Type": "AWS::EC2::Route",
"DependsOn": "AttachGateway",
"Properties": {
"RouteTableId": {"Ref": "PublicRouteTable"},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {"Ref": "myInternetGateway"},
},
},
"PublicSubnetRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"SubnetId": {"Ref": "PublicSubnet"},
"RouteTableId": {"Ref": "PublicRouteTable"},
},
},
},
"Outputs": {
"ClusterEndpoint": {
"Description": "Cluster endpoint",
"Value": {
"Fn::Join": [
":",
[
{"Fn::GetAtt": ["RedshiftCluster", "Endpoint.Address"]},
{"Fn::GetAtt": ["RedshiftCluster", "Endpoint.Port"]},
],
]
},
},
"ClusterName": {
"Description": "Name of cluster",
"Value": {"Ref": "RedshiftCluster"},
},
"ParameterGroupName": {
"Description": "Name of parameter group",
"Value": {"Ref": "RedshiftClusterParameterGroup"},
},
"RedshiftClusterSubnetGroupName": {
"Description": "Name of cluster subnet group",
"Value": {"Ref": "RedshiftClusterSubnetGroup"},
},
"RedshiftClusterSecurityGroupName": {
"Description": "Name of cluster security group",
"Value": {"Ref": "SecurityGroup"},
},
},
}
|