-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate1.yaml
197 lines (168 loc) · 4.64 KB
/
template1.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
AWSTemplateFormatVersion: 2010-09-09
Description: Lab template
# Lab VPC with public subnet and Internet Gateway
Parameters:
LabVpcCidr:
Type: String
Default: 10.0.0.0/20
PublicSubnetCidr:
Type: String
Default: 10.0.0.0/24
AmazonLinuxAMIID:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
KeyName:
Type: String
Description: Keyname for the keypair that you will use to connect to the Web Server EC2 instance
Default: default-lab-key
Resources:
###########
# VPC with Internet Gateway
###########
LabVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref LabVpcCidr
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: Lab VPC
IGW:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: Lab IGW
VPCtoIGWConnection:
Type: AWS::EC2::VPCGatewayAttachment
DependsOn:
- IGW
- LabVPC
Properties:
InternetGatewayId: !Ref IGW
VpcId: !Ref LabVPC
###########
# Public Route Table
###########
PublicRouteTable:
Type: AWS::EC2::RouteTable
DependsOn: LabVPC
Properties:
VpcId: !Ref LabVPC
Tags:
- Key: Name
Value: Public Route Table
PublicRoute:
Type: AWS::EC2::Route
DependsOn:
- PublicRouteTable
- IGW
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref IGW
RouteTableId: !Ref PublicRouteTable
###########
# Public Subnet
###########
PublicSubnet:
Type: AWS::EC2::Subnet
DependsOn: LabVPC
Properties:
VpcId: !Ref LabVPC
MapPublicIpOnLaunch: true
CidrBlock: !Ref PublicSubnetCidr
AvailabilityZone: !Select
- 0
- !GetAZs
Ref: AWS::Region
Tags:
- Key: Name
Value: Public Subnet
PublicRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
DependsOn:
- PublicRouteTable
- PublicSubnet
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet
###########
# EC2 Instance
###########
WebServerInstance:
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref AmazonLinuxAMIID
KeyName: !Ref KeyName
InstanceType: t3.micro
SecurityGroupIds:
- !Ref WebSecurityGroup
SubnetId: !Ref PublicSubnet
Tags:
- Key: Name
Value: Web Server
UserData:
Fn::Base64: !Sub |
#!/bin/bash -ex
hostnamectl set-hostname Web-Server
yum install -y httpd
echo '<html><h1>Hello from your web server!</h1>' > /var/www/html/index.html
echo '<h2>AWS re/Start MXMEX9 | Coding Dojo</h2>' >> /var/www/html/index.html
echo '<p>Proyecto: CafeCloudWeb</p>' >> /var/www/html/index.html
echo '<h2>Integrantes:</h2>' >> /var/www/html/index.html
echo '<ul>' >> /var/www/html/index.html
echo '<li>Brenda Díaz</li>' >> /var/www/html/index.html
echo '<li>Gloria Nabor</li>' >> /var/www/html/index.html
echo '<li>Miriam Almanza</li>' >> /var/www/html/index.html
echo '<li>Moisés Solorio</li>' >> /var/www/html/index.html
echo '<li>Nancy Contreras</li>' >> /var/www/html/index.html
echo '</ul></html>' >> /var/www/html/index.html
systemctl enable httpd
systemctl start httpd
/opt/aws/bin/cfn-signal -s true '${WaitHandle}'
WaitHandle:
Type: AWS::CloudFormation::WaitConditionHandle
WaitCondition:
Type: AWS::CloudFormation::WaitCondition
DependsOn: WebServerInstance
Properties:
Handle: !Ref WaitHandle
Timeout: '60'
###########
# Web Security Group
###########
WebSecurityGroup:
Type: AWS::EC2::SecurityGroup
DependsOn: LabVPC
Properties:
GroupName: WebServerSG
GroupDescription: Enable access to web server
VpcId: !Ref LabVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '22'
ToPort: '23'
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: WebServerSG
###########
# S3
###########
MyBucket:
Type: AWS::S3::Bucket
###########
# Outputs
###########
Outputs:
BucketName:
Value: !Sub ${MyBucket}
PublicIP:
Value: !GetAtt
- WebServerInstance
- PublicIp