Skip to content

Instantly share code, notes, and snippets.

Embed
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"
}
]
}
},
"InternetFacingRouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"Tags": [
{
"Key": "Name",
"Value": {
"Ref": "AWS::StackName"
}
}
]
}
}
@mattc41190

This comment has been minimized.

Copy link

mattc41190 commented Mar 13, 2019

Looks awesome, very simple to port to Terraform as well.

Are there any lessons learned from the pattern? At time of this comment no revisions have been made and it's been over a year since publication. In any-case this is a great example of clean infrastructure provisioning. Thank you for your contribution.

@mohanr

This comment has been minimized.

Copy link

mohanr commented Jun 7, 2019

I see this error.
6/7/2019, 5:01:01 PM - Cannot render the template because of an error.: YAMLException: end of the stream or a document separator is expected at line 35, column 10: }, ^

@Glamdring

This comment has been minimized.

Copy link
Owner Author

Glamdring commented Jun 7, 2019

I see this error.
6/7/2019, 5:01:01 PM - Cannot render the template because of an error.: YAMLException: end of the stream or a document separator is expected at line 35, column 10: }, ^

It's JSON, not YAML

@mohanr

This comment has been minimized.

Copy link

mohanr commented Jun 9, 2019

Yes. But the cloudformation designer will convert it automatically if it is valid JSON. It does if I enclose the current JSON with {}. Even the JSON linter needs it.

@Glamdring

This comment has been minimized.

Copy link
Owner Author

Glamdring commented Jun 9, 2019

It's not a full cloudformation script, only a partial snippet. You have to fit it into a bigger one

@souuu

This comment has been minimized.

Copy link

souuu commented Jul 9, 2019

InternetFacingRouteTable and many other resources are missing

@Glamdring

This comment has been minimized.

Copy link
Owner Author

Glamdring commented Jul 10, 2019

Added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.