Created
November 1, 2020 19:04
-
-
Save peteoleary/fe3e9267d779fac9aa7e93f5d5e5964c to your computer and use it in GitHub Desktop.
Cloud Formation Tiered Web App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Description": "Description here.", | |
"Parameters": { | |
"SubnetAvailabilityZone1": { | |
"Description": "Availability Zone for Subnet 1", | |
"Type": "String", | |
"Default": "us-west-2a" | |
}, | |
"SubnetAvailabilityZone2": { | |
"Description": "Availability Zone for Subnet 2", | |
"Type": "String", | |
"Default": "us-west-2b" | |
}, | |
"KeyName": { | |
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances", | |
"Type": "AWS::EC2::KeyPair::KeyName", | |
"ConstraintDescription": "must be the name of an existing EC2 KeyPair." | |
}, | |
"InstanceType": { | |
"Description": "WebServer EC2 instance type", | |
"Type": "String", | |
"Default": "t2.small", | |
"AllowedValues": [ | |
"t1.micro", | |
"t2.nano", | |
"t2.micro", | |
"t2.small", | |
"t2.medium", | |
"t2.large", | |
"m1.small", | |
"m1.medium", | |
"m1.large", | |
"m1.xlarge", | |
"m2.xlarge", | |
"m2.2xlarge", | |
"m2.4xlarge", | |
"m3.medium", | |
"m3.large", | |
"m3.xlarge", | |
"m3.2xlarge", | |
"m4.large", | |
"m4.xlarge", | |
"m4.2xlarge", | |
"m4.4xlarge", | |
"m4.10xlarge", | |
"c1.medium", | |
"c1.xlarge", | |
"c3.large", | |
"c3.xlarge", | |
"c3.2xlarge", | |
"c3.4xlarge", | |
"c3.8xlarge", | |
"c4.large", | |
"c4.xlarge", | |
"c4.2xlarge", | |
"c4.4xlarge", | |
"c4.8xlarge", | |
"g2.2xlarge", | |
"g2.8xlarge", | |
"r3.large", | |
"r3.xlarge", | |
"r3.2xlarge", | |
"r3.4xlarge", | |
"r3.8xlarge", | |
"i2.xlarge", | |
"i2.2xlarge", | |
"i2.4xlarge", | |
"i2.8xlarge", | |
"d2.xlarge", | |
"d2.2xlarge", | |
"d2.4xlarge", | |
"d2.8xlarge", | |
"hi1.4xlarge", | |
"hs1.8xlarge", | |
"cr1.8xlarge", | |
"cc2.8xlarge", | |
"cg1.4xlarge" | |
], | |
"ConstraintDescription": "must be a valid EC2 instance type." | |
}, | |
"SSHLocation": { | |
"Description": "The IP address range that can be used to SSH to the EC2 instances", | |
"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 IP CIDR range of the form x.x.x.x/x." | |
}, | |
"WebServerCapacity": { | |
"Default": "1", | |
"Description": "The initial number of WebServer instances", | |
"Type": "Number", | |
"MinValue": "1", | |
"MaxValue": "5", | |
"ConstraintDescription": "must be between 1 and 5 EC2 instances." | |
}, | |
"AdminAppImage": { | |
"Description": "Image for App server. Must be in the same region as other Resources", | |
"Type": "String", | |
"Default": "ami-07a29e5e945228fa1" | |
}, | |
"CustomerAppImage": { | |
"Description": "Image for Customer server. Must be in the same region as other Resources", | |
"Type": "String", | |
"Default": "ami-07a29e5e945228fa1" | |
}, | |
"APIServerImage": { | |
"Description": "Image for API server. Must be in the same region as other Resources", | |
"Type": "String", | |
"Default": "ami-07a29e5e945228fa1" | |
} | |
}, | |
"Resources": { | |
"AppLoadBalancer": { | |
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer", | |
"Properties": { | |
"Subnets": [ | |
{ | |
"Ref": "AppSubnet1" | |
}, | |
{ | |
"Ref": "AppSubnet2" | |
} | |
] | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "54377670-4b84-49f7-9546-d6836316a4ac" | |
} | |
} | |
}, | |
"CustomerAppTargetGroup": { | |
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup", | |
"Properties": { | |
"VpcId" : {"Ref": "VPC"}, | |
"Port" : 80, | |
"Protocol" : "HTTP", | |
"Targets": [ | |
] | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "3e79f579-6393-47b9-84a7-9c6a2aac6ede" | |
} | |
} | |
}, | |
"APITargetGroup": { | |
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup", | |
"Properties": { | |
"VpcId" : {"Ref": "VPC"}, | |
"Port" : 8080, | |
"Protocol" : "TCP", | |
"Targets": [ | |
] | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "67f75b3d-ed07-480a-8dbc-26d79af8df7d" | |
} | |
} | |
}, | |
"APILoadBalancer": { | |
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer", | |
"Properties": { | |
"Type": "network", | |
"Subnets": [ | |
{ | |
"Ref": "APISubnet1" | |
}, | |
{ | |
"Ref": "APISubnet2" | |
} | |
] | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "0eeadd9d-05ed-4784-abc0-642e5120c005" | |
} | |
} | |
}, | |
"AdminAppTargetGroup": { | |
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup", | |
"Properties": { | |
"VpcId" : {"Ref": "VPC"}, | |
"Port" : 80, | |
"Protocol" : "HTTP", | |
"Targets": [ | |
] | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "45800956-4c26-48ba-8237-274ab5065908" | |
} | |
} | |
}, | |
"AppHTTPListener": { | |
"Type": "AWS::ElasticLoadBalancingV2::Listener", | |
"Properties": { | |
"Protocol" : "HTTP", | |
"Port": 80, | |
"DefaultActions": [ | |
{ | |
"Order": 1, | |
"Type": "forward", | |
"TargetGroupArn": { | |
"Ref": "CustomerAppTargetGroup" | |
} | |
} | |
], | |
"LoadBalancerArn": { | |
"Ref": "AppLoadBalancer" | |
} | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "9eeaa1f3-b9d0-4fb0-bf0b-6a875b07d4b0" | |
} | |
} | |
}, | |
"APIListener": { | |
"Type": "AWS::ElasticLoadBalancingV2::Listener", | |
"Properties": { | |
"Protocol": "TCP", | |
"Port": 8080, | |
"DefaultActions": [ | |
{ | |
"Order": 1, | |
"Type": "forward", | |
"TargetGroupArn": { | |
"Ref": "APITargetGroup" | |
} | |
} | |
], | |
"LoadBalancerArn": { | |
"Ref": "APILoadBalancer" | |
} | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "9eeaa1f3-b9d0-4fb0-bf0b-6a875b07d4b0" | |
} | |
} | |
}, | |
"AppSubnet1": { | |
"Type": "AWS::EC2::Subnet", | |
"Properties": { | |
"VpcId": { | |
"Ref": "VPC" | |
}, | |
"AvailabilityZone": { | |
"Ref": "SubnetAvailabilityZone1" | |
}, | |
"CidrBlock": "10.0.0.0/24" | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "34277c6f-ff64-4031-bc13-228abe0a77e4" | |
} | |
} | |
}, | |
"AppSubnet2": { | |
"Type": "AWS::EC2::Subnet", | |
"Properties": { | |
"VpcId": { | |
"Ref": "VPC" | |
}, | |
"AvailabilityZone": { | |
"Ref": "SubnetAvailabilityZone2" | |
}, | |
"CidrBlock": "10.0.1.0/24" | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "bdcb12bc-7bfb-4368-9fba-0469501d29df" | |
} | |
} | |
}, | |
"APISubnet1": { | |
"Type": "AWS::EC2::Subnet", | |
"Properties": { | |
"VpcId": { | |
"Ref": "VPC" | |
}, | |
"AvailabilityZone": { | |
"Ref": "SubnetAvailabilityZone1" | |
}, | |
"CidrBlock": "10.0.2.0/24" | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "333c1bc0-0e62-49cf-b182-53272caadb9f" | |
} | |
} | |
}, | |
"APISubnet2": { | |
"Type": "AWS::EC2::Subnet", | |
"Properties": { | |
"VpcId": { | |
"Ref": "VPC" | |
}, | |
"AvailabilityZone": { | |
"Ref": "SubnetAvailabilityZone2" | |
}, | |
"CidrBlock": "10.0.3.0/24" | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "5620a319-357e-49cc-9ce9-85c9dd7d0879" | |
} | |
} | |
}, | |
"APISecurityGroup": { | |
"Type": "AWS::EC2::SecurityGroup", | |
"Properties": { | |
"GroupDescription": "Open database for access", | |
"SecurityGroupIngress": [ | |
{ | |
"IpProtocol": "tcp", | |
"FromPort": "3306", | |
"ToPort": "3306", | |
"SourceSecurityGroupId": { | |
"Ref": "AppSecurityGroup" | |
} | |
} | |
], | |
"VpcId": { | |
"Ref": "VPC" | |
} | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "b8052b79-4c51-4834-ba8c-c8d04a37ed85" | |
} | |
} | |
}, | |
"AppSecurityGroup": { | |
"Type": "AWS::EC2::SecurityGroup", | |
"Properties": { | |
"GroupDescription": "Enable HTTP access via port 80 locked down to the load balancer + SSH access", | |
"SecurityGroupIngress": [ | |
{ | |
"IpProtocol": "tcp", | |
"FromPort": "80", | |
"ToPort": "80" | |
}, | |
{ | |
"IpProtocol": "tcp", | |
"FromPort": "22", | |
"ToPort": "22", | |
"CidrIp": { | |
"Ref": "SSHLocation" | |
} | |
} | |
], | |
"VpcId": { | |
"Ref": "VPC" | |
} | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "f5f84b37-fb34-41b6-9bb6-b51df725ad21" | |
} | |
} | |
}, | |
"AdminAppServer": { | |
"Type": "AWS::EC2::Instance", | |
"Properties": { | |
"ImageId" : {"Ref": "AdminAppImage"}, | |
"NetworkInterfaces": [ | |
{ | |
"SubnetId": { | |
"Ref": "AppSubnet1" | |
}, | |
"DeviceIndex": "0", | |
"GroupSet": [ | |
{ | |
"Ref": "AppSecurityGroup" | |
} | |
] | |
} | |
] | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "03fbe94d-c140-41df-9d89-d216e45f2e58" | |
} | |
} | |
}, | |
"APIServer": { | |
"Type": "AWS::EC2::Instance", | |
"Properties": { | |
"ImageId" : {"Ref": "APIServerImage"}, | |
"NetworkInterfaces": [ | |
{ | |
"SubnetId": { | |
"Ref": "APISubnet1" | |
}, | |
"DeviceIndex": "0", | |
"GroupSet": [ | |
{ | |
"Ref": "APISecurityGroup" | |
} | |
] | |
} | |
] | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "ef121cd7-4268-4c9c-8b2f-5f97f027f9d3" | |
} | |
} | |
}, | |
"CustomerAppServer": { | |
"Type": "AWS::EC2::Instance", | |
"Properties": { | |
"ImageId" : {"Ref": "CustomerAppImage"}, | |
"NetworkInterfaces": [ | |
{ | |
"SubnetId": { | |
"Ref": "AppSubnet1" | |
}, | |
"DeviceIndex": "0", | |
"GroupSet": [ | |
{ | |
"Ref": "AppSecurityGroup" | |
} | |
] | |
} | |
] | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "1cdfad39-a270-43d2-9242-f19b02054873" | |
} | |
} | |
}, | |
"VPC": { | |
"Type": "AWS::EC2::VPC", | |
"Properties": { | |
"CidrBlock": "10.0.0.0/16" | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "2160bcaf-c7df-44b5-ba08-ea9b9b39d56c" | |
} | |
} | |
}, | |
"InternetGateway": { | |
"Type": "AWS::EC2::InternetGateway", | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "b292bd84-f885-4496-ba1d-7b852d2199e7" | |
} | |
} | |
}, | |
"InternetGatewayAttachment": { | |
"Type": "AWS::EC2::VPCGatewayAttachment", | |
"Properties": { | |
"InternetGatewayId": { | |
"Ref": "InternetGateway" | |
}, | |
"VpcId": { | |
"Ref": "VPC" | |
} | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"id": "2f39b3a4-0672-49c2-aa74-994c07ae5f9c" | |
} | |
} | |
} | |
}, | |
"Metadata": { | |
"AWS::CloudFormation::Designer": { | |
"f5f84b37-fb34-41b6-9bb6-b51df725ad21": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 480, | |
"y": 90 | |
}, | |
"z": 1, | |
"embeds": [], | |
"iscontainedinside": [ | |
"2160bcaf-c7df-44b5-ba08-ea9b9b39d56c" | |
] | |
}, | |
"b8052b79-4c51-4834-ba8c-c8d04a37ed85": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 480, | |
"y": 210 | |
}, | |
"z": 1, | |
"embeds": [], | |
"iscontainedinside": [ | |
"2160bcaf-c7df-44b5-ba08-ea9b9b39d56c" | |
] | |
}, | |
"5620a319-357e-49cc-9ce9-85c9dd7d0879": { | |
"size": { | |
"width": 150, | |
"height": 150 | |
}, | |
"position": { | |
"x": 1290, | |
"y": 300 | |
}, | |
"z": 1, | |
"embeds": [], | |
"iscontainedinside": [ | |
"2160bcaf-c7df-44b5-ba08-ea9b9b39d56c" | |
] | |
}, | |
"333c1bc0-0e62-49cf-b182-53272caadb9f": { | |
"size": { | |
"width": 150, | |
"height": 150 | |
}, | |
"position": { | |
"x": 1110, | |
"y": 270 | |
}, | |
"z": 1, | |
"embeds": [], | |
"iscontainedinside": [ | |
"2160bcaf-c7df-44b5-ba08-ea9b9b39d56c" | |
] | |
}, | |
"bdcb12bc-7bfb-4368-9fba-0469501d29df": { | |
"size": { | |
"width": 150, | |
"height": 150 | |
}, | |
"position": { | |
"x": 1290, | |
"y": 90 | |
}, | |
"z": 1, | |
"embeds": [], | |
"iscontainedinside": [ | |
"2160bcaf-c7df-44b5-ba08-ea9b9b39d56c" | |
] | |
}, | |
"34277c6f-ff64-4031-bc13-228abe0a77e4": { | |
"size": { | |
"width": 150, | |
"height": 150 | |
}, | |
"position": { | |
"x": 900, | |
"y": 90 | |
}, | |
"z": 1, | |
"embeds": [], | |
"iscontainedinside": [ | |
"2160bcaf-c7df-44b5-ba08-ea9b9b39d56c" | |
] | |
}, | |
"45800956-4c26-48ba-8237-274ab5065908": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 480, | |
"y": 330 | |
}, | |
"z": 1, | |
"embeds": [] | |
}, | |
"0eeadd9d-05ed-4784-abc0-642e5120c005": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 480, | |
"y": 450 | |
}, | |
"z": 1, | |
"embeds": [], | |
"iscontainedinside": [ | |
"333c1bc0-0e62-49cf-b182-53272caadb9f", | |
"5620a319-357e-49cc-9ce9-85c9dd7d0879" | |
] | |
}, | |
"67f75b3d-ed07-480a-8dbc-26d79af8df7d": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 60, | |
"y": 510 | |
}, | |
"z": 1, | |
"embeds": [] | |
}, | |
"3e79f579-6393-47b9-84a7-9c6a2aac6ede": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 180, | |
"y": 510 | |
}, | |
"z": 1, | |
"embeds": [] | |
}, | |
"54377670-4b84-49f7-9546-d6836316a4ac": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 300, | |
"y": 510 | |
}, | |
"z": 1, | |
"embeds": [], | |
"iscontainedinside": [ | |
"34277c6f-ff64-4031-bc13-228abe0a77e4", | |
"bdcb12bc-7bfb-4368-9fba-0469501d29df" | |
] | |
}, | |
"9eeaa1f3-b9d0-4fb0-bf0b-6a875b07d4b0": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 540, | |
"y": 570 | |
}, | |
"z": 1, | |
"embeds": [], | |
"isassociatedwith": [ | |
"54377670-4b84-49f7-9546-d6836316a4ac" | |
] | |
}, | |
"8547030b-1911-458d-95b5-ebd841124ced": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 600, | |
"y": 90 | |
}, | |
"z": 1, | |
"embeds": [], | |
"isassociatedwith": [ | |
"54377670-4b84-49f7-9546-d6836316a4ac" | |
] | |
}, | |
"03fbe94d-c140-41df-9d89-d216e45f2e58": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 750, | |
"y": 330 | |
}, | |
"z": 1, | |
"embeds": [], | |
"isassociatedwith": [ | |
"f5f84b37-fb34-41b6-9bb6-b51df725ad21" | |
], | |
"iscontainedinside": [ | |
"34277c6f-ff64-4031-bc13-228abe0a77e4" | |
] | |
}, | |
"ef121cd7-4268-4c9c-8b2f-5f97f027f9d3": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 930, | |
"y": 390 | |
}, | |
"z": 1, | |
"embeds": [], | |
"isassociatedwith": [ | |
"b8052b79-4c51-4834-ba8c-c8d04a37ed85" | |
], | |
"iscontainedinside": [ | |
"333c1bc0-0e62-49cf-b182-53272caadb9f" | |
] | |
}, | |
"1cdfad39-a270-43d2-9242-f19b02054873": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 660, | |
"y": 240 | |
}, | |
"z": 1, | |
"embeds": [], | |
"isassociatedwith": [ | |
"f5f84b37-fb34-41b6-9bb6-b51df725ad21" | |
], | |
"iscontainedinside": [ | |
"34277c6f-ff64-4031-bc13-228abe0a77e4" | |
] | |
}, | |
"2160bcaf-c7df-44b5-ba08-ea9b9b39d56c": { | |
"size": { | |
"width": 150, | |
"height": 150 | |
}, | |
"position": { | |
"x": 1140, | |
"y": 120 | |
}, | |
"z": 1, | |
"embeds": [] | |
}, | |
"b292bd84-f885-4496-ba1d-7b852d2199e7": { | |
"size": { | |
"width": 60, | |
"height": 60 | |
}, | |
"position": { | |
"x": 60, | |
"y": 90 | |
}, | |
"z": 1, | |
"embeds": [] | |
}, | |
"2f39b3a4-0672-49c2-aa74-994c07ae5f9c": { | |
"source": { | |
"id": "2160bcaf-c7df-44b5-ba08-ea9b9b39d56c" | |
}, | |
"target": { | |
"id": "b292bd84-f885-4496-ba1d-7b852d2199e7" | |
}, | |
"z": 0 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment