Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
"PrivateSubnetA": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
0,
{
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
}
]
},
"VpcId": {
"Ref": "VPC"
},
"CidrBlock": {
"Fn::Select": [
"0",
{
"Ref": "PrivateSubnetRanges"
}
]
},
"Tags": [
{
"Key": "Name",
"Value": {
"Ref": "AWS::StackName"
}
}
]
}
},
"PrivateSubnetB": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
1,
{
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
}
]
},
"VpcId": {
"Ref": "VPC"
},
"CidrBlock": {
"Fn::Select": [
"1",
{
"Ref": "PrivateSubnetRanges"
}
]
},
"Tags": [
{
"Key": "Name",
"Value": {
"Ref": "AWS::StackName"
}
}
]
}
},
"PrivateSubnetC": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
2,
{
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
}
]
},
"VpcId": {
"Ref": "VPC"
},
"CidrBlock": {
"Fn::Select": [
"2",
{
"Ref": "PrivateSubnetRanges"
}
]
},
"Tags": [
{
"Key": "Name",
"Value": {
"Ref": "AWS::StackName"
}
}
]
}
},
"PrivateSubnetARouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "InternetFacingRouteTable"
},
"SubnetId": {
"Ref": "PrivateSubnetA"
}
}
},
"PrivateSubnetBRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "InternetFacingRouteTable"
},
"SubnetId": {
"Ref": "PrivateSubnetB"
}
}
},
"PrivateSubnetCRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "InternetFacingRouteTable"
},
"SubnetId": {
"Ref": "PrivateSubnetC"
}
}
},
"DatabaseSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Enable outbound HTTP(S) connections and inbound SSH and Cassandra TCP",
"VpcId": {
"Ref": "VPC"
},
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "9042",
"ToPort": "9042",
"CidrIp": {
"Ref": "VpcCIDR"
}
},
{
"IpProtocol": "tcp",
"FromPort": "7000",
"ToPort": "7000",
"CidrIp": {
"Ref": "VpcCIDR"
}
},
{
"IpProtocol": "tcp",
"FromPort": "7001",
"ToPort": "7001",
"CidrIp": {
"Ref": "VpcCIDR"
}
},
{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": {
"Ref": "VpcCIDR"
}
}
],
"SecurityGroupEgress": [
{
"CidrIp": "0.0.0.0/0",
"FromPort": "80",
"IpProtocol": "tcp",
"ToPort": "80"
},
{
"CidrIp": "0.0.0.0/0",
"FromPort": "443",
"IpProtocol": "tcp",
"ToPort": "443"
},
{
"IpProtocol": "tcp",
"FromPort": "7000",
"ToPort": "7000",
"CidrIp": {
"Ref": "VpcCIDR"
}
},
{
"IpProtocol": "tcp",
"FromPort": "7001",
"ToPort": "7001",
"CidrIp": {
"Ref": "VpcCIDR"
}
}
]
}
},
"DatabaseLoadBalancer": {
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
"Properties": {
"Name": "DatabaseLoadBalancer",
"Scheme": "internal",
"Type": "network",
"Subnets": [
{
"Ref": "PrivateSubnetA"
},
{
"Ref": "PrivateSubnetB"
},
{
"Ref": "PrivateSubnetC"
}
]
}
},
"DatabaseTargetGroup": {
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
"Properties": {
"Name": "DatabaseTargetGroup",
"Port": 9042,
"Protocol": "TCP",
"VpcId": {
"Ref": "VPC"
}
}
},
"DatabaseALBListenerTCP": {
"Type": "AWS::ElasticLoadBalancingV2::Listener",
"Properties": {
"DefaultActions": [
{
"Type": "forward",
"TargetGroupArn": {
"Ref": "DatabaseTargetGroup"
}
}
],
"LoadBalancerArn": {
"Ref": "DatabaseLoadBalancer"
},
"Port": "9042",
"Protocol": "TCP"
}
},
"DatabaseLaunchConfiguration": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"AssociatePublicIpAddress": true,
"IamInstanceProfile": {
"Ref": "InstanceRoleInstanceProfile"
},
"ImageId": {
"Fn::FindInMap": [
"RegionOS2AMI",
{
"Ref": "AWS::Region"
},
"Linux"
]
},
"InstanceType": {
"Ref": "DatabaseInstanceType"
},
"KeyName": {
"Ref": "KeyPairName"
},
"SecurityGroups": [
{
"Ref": "DatabaseSecurityGroup"
}
],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash -x\n",
"yum update -y aws-cfn-bootstrap\n",
"yum install -y aws-cli\n",
"#this runs the first stage of cfinit\n",
{
"Fn::Join": [
"",
[
"/opt/aws/bin/cfn-init -v --region ",
{
"Ref": "AWS::Region"
},
" -s ",
{
"Ref": "AWS::StackName"
},
" -r ",
"DatabaseAutoScalingGroup"
]
]
},
"\n",
". /tmp/install/setup-cassandra.sh ",
{
"Ref": "NodeSetupBucketName"
},
"\n",
"# All is well, so signal success.\n",
"/opt/aws/bin/cfn-signal -e 0 -r \"Database group started.\" '",
{
"Ref": "DatabaseWaitHandle"
},
"'\n"
]
]
}
}
}
},
"DatabaseAutoScalingGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Metadata": {
"AWS::CloudFormation::Authentication": {
"S3AccessCreds": {
"buckets": [
{
"Ref": "NodeSetupBucketName"
}
],
"roleName": {
"Ref": "InstanceRole"
},
"type": "S3"
}
},
"AWS::CloudFormation::Init": {
"config": {
"files": {
"/tmp/install/setup-cassandra.sh": {
"mode": "000755",
"source": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "NodeSetupBucketName"
},
".s3-",
{
"Ref": "AWS::Region"
},
".amazonaws.com/setup-cassandra.sh"
]
]
}
},
"/tmp/install/update-cassandra-cluster-config.py": {
"mode": "000755",
"source": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "NodeSetupBucketName"
},
".s3-",
{
"Ref": "AWS::Region"
},
".amazonaws.com/update-cassandra-cluster-config.py"
]
]
}
}
}
}
}
},
"Properties": {
"AvailabilityZones": {
"Fn::GetAZs": {
"Ref": "AWS::Region"
}
},
"LaunchConfigurationName": {
"Ref": "DatabaseLaunchConfiguration"
},
"TargetGroupARNs": [
{
"Ref": "DatabaseTargetGroup"
}
],
"MaxSize": {
"Ref": "MaxDatabaseGroupSize"
},
"MinSize": "1",
"DesiredCapacity": {
"Ref": "DatabaseGroupSize"
},
"VPCZoneIdentifier": [
{
"Ref": "PrivateSubnetA"
},
{
"Ref": "PrivateSubnetB"
},
{
"Ref": "PrivateSubnetC"
}
],
"Tags": [
{
"Key": "Name",
"PropagateAtLaunch": "true",
"Value": "DatabaseNode"
}
]
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment