-
Notifications
You must be signed in to change notification settings - Fork 0
/
AWS-STL-Meetup-12.yaml
159 lines (134 loc) · 3.52 KB
/
AWS-STL-Meetup-12.yaml
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
# Add a NAT Gateway
Parameters:
VpcCidr:
Default: 10.10.0.0/16
Type: String
PublicSubnetCidr:
Default: 10.10.0.0/24
Type: String
PrivateSubnetCidr:
Default: 10.10.1.0/24
Type: String
ImageId:
Default: ami-0d8f6eb4f641ef691
Type: String
InstanceType:
Default: t3.micro
Type: String
KeyName:
Default: AWS-STL-Meetup
Type: String
WebInstanceIp:
Default: 10.10.0.10
Type: String
BackendInstanceIp:
Default: 10.10.1.10
Type: String
Resources:
Vpc:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: !Ref VpcCidr
InternetGateway:
Type: "AWS::EC2::InternetGateway"
InternetGatewayAttachment:
Type: "AWS::EC2::VPCGatewayAttachment"
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref Vpc
NatGatewayElasticIp:
Type: "AWS::EC2::EIP"
NatGateway:
Type: "AWS::EC2::NatGateway"
Properties:
AllocationId: !Ref NatGatewayElasticIp
SubnetId: !Ref PublicSubnet
PublicSubnet:
Type: "AWS::EC2::Subnet"
Properties:
CidrBlock: !Ref PublicSubnetCidr
VpcId: !Ref Vpc
PublicSubnetRouteTable:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId: !Ref Vpc
PublicSubnetRouteTableAssociation:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
RouteTableId: !Ref PublicSubnetRouteTable
SubnetId: !Ref PublicSubnet
PublicSubnetDefaultRoute:
Type: "AWS::EC2::Route"
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
RouteTableId: !Ref PublicSubnetRouteTable
PrivateSubnet:
Type: "AWS::EC2::Subnet"
Properties:
CidrBlock: !Ref PrivateSubnetCidr
VpcId: !Ref Vpc
PrivateSubnetRouteTable:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId: !Ref Vpc
PrivateSubnetRouteTableAssociation:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
RouteTableId: !Ref PrivateSubnetRouteTable
SubnetId: !Ref PrivateSubnet
WebSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: Web Security Group
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: tcp
ToPort: 80
- CidrIp: 0.0.0.0/0
FromPort: -1
IpProtocol: icmp
ToPort: -1
VpcId: !Ref Vpc
WebInstance:
Type: "AWS::EC2::Instance"
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
KeyName: !Ref KeyName
SecurityGroupIds:
- !Ref WebSecurityGroup
SubnetId: !Ref PublicSubnet
PrivateIpAddress: !Ref WebInstanceIp
UserData:
Fn::Base64:
!Sub |
#!/bin/bash
amazon-linux-extras install nginx1.12
service nginx start
chkconfig nginx on
WebInstanceElasticIp:
Type: "AWS::EC2::EIP"
Properties:
InstanceId: !Ref WebInstance
BackendSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: Backend Security Group
SecurityGroupIngress:
- SourceSecurityGroupId: !Ref WebSecurityGroup
FromPort: 80
IpProtocol: tcp
ToPort: 80
VpcId: !Ref Vpc
BackendInstance:
Type: "AWS::EC2::Instance"
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
KeyName: !Ref KeyName
SecurityGroupIds:
- !Ref BackendSecurityGroup
SubnetId: !Ref PrivateSubnet
PrivateIpAddress: !Ref BackendInstanceIp