-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-stack.yml
131 lines (126 loc) · 3.54 KB
/
server-stack.yml
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
Description: Create Web servers and ELB
Parameters:
VPCID:
Type: "AWS::EC2::VPC::Id"
Description: Enter a valid VPC Id
PrivateSubnet1:
Type: "AWS::EC2::Subnet::Id"
Description: Enter a valid SubnetId of private subnet in AZ1
PrivateSubnet2:
Type: "AWS::EC2::Subnet::Id"
Description: Enter a valid SubnetId of private subnet in AZ2
PublicSubnet1:
Type: "AWS::EC2::Subnet::Id"
Description: Enter a valid SubnetId of public subnet in AZ1
PublicSubnet2:
Type: "AWS::EC2::Subnet::Id"
Description: Enter a valid SubnetId of public subnet in AZ2
KeyPair:
Type: "AWS::EC2::KeyPair::KeyName"
Description: Enter a valid KeyPair Name
AMIId:
Type: "AWS::EC2::Image::Id"
Description: Enter a valid AMI ID to launch the instance
WebSG:
Type: "AWS::EC2::SecurityGroup::Id"
Description: Enter a valid security group ID for web server
DBClientSG:
Type: "AWS::EC2::SecurityGroup::Id"
Description: Enter a valid security group ID for web server to enable DB access
ELBSG:
Type: "AWS::EC2::SecurityGroup::Id"
Description: Enter a valid security group ID for ELB
WebIAMProfile:
Type: String
Description: Enter ARN of IAM Instance Profile to be attached to web server
WebInstanceType:
Type: String
Description: Enter one of the possible instance type for web server
AllowedValues:
- t2.large
- m4.large
- m4.xlarge
- c4.large
WebMinSize:
Type: String
Description: Minimum number of instances in auto scaling group
WebMaxSize:
Type: String
Description: Maximum number of instances in auto scaling group
Environment:
Type: String
Description: Select the appropriate environment
AllowedValues:
- dev
- test
- uat
- prod
Resources:
WebELB:
Type: "AWS::ElasticLoadBalancing::LoadBalancer"
Properties:
LoadBalancerName:
Fn::Sub: WebELB-${Environment}
Scheme: internet-facing
CrossZone: true
Subnets:
- Ref: PublicSubnet1
- Ref: PublicSubnet2
SecurityGroups:
- Ref: ELBSG
Listeners:
- LoadBalancerPort: '80'
InstancePort: '80'
Protocol: HTTP
HealthCheck:
Target: HTTP:80/
HealthyThreshold: '3'
UnhealthyThreshold: '5'
Interval: '6'
Timeout: '5'
ConnectionDrainingPolicy:
Enabled: 'true'
Timeout: '60'
Tags:
- Key: Name
Value:
Fn::Sub: WebELB-${Environment}
WebServerLaunchConfig:
Type: "AWS::AutoScaling::LaunchConfiguration"
Properties:
KeyName:
Ref: KeyPair
ImageId:
Ref: AMIId
UserData: IyEvYmluL2Jhc2gNCnl1bSB1cGRhdGUgLXkNCnl1bSBpbnN0YWxsIC15IGh0dHBkMjQNCnNlcnZpY2UgaHR0cGQgc3RhcnQNCmNoa2NvbmZpZyBodHRwZCBvbg==
SecurityGroups:
- Ref: WebSG
- Ref: DBClientSG
InstanceType:
Ref: WebInstanceType
IamInstanceProfile:
Ref: WebIAMProfile
WebServerASG:
Type: "AWS::AutoScaling::AutoScalingGroup"
Properties:
VPCZoneIdentifier:
- Ref: PrivateSubnet1
- Ref: PrivateSubnet2
LaunchConfigurationName:
Ref: "WebServerLaunchConfig"
MinSize:
Ref: WebMinSize
MaxSize:
Ref: WebMaxSize
LoadBalancerNames:
- Ref: "WebELB"
Tags:
- Key: Name
Value:
Fn::Sub: WebServer-${Environment}
PropagateAtLaunch: true
Outputs:
WebELBURL:
Description: "URL endpoint of web ELB"
Value:
Fn::GetAtt: [ WebELB, DNSName ]