-
Notifications
You must be signed in to change notification settings - Fork 0
/
VPC2R53.yml
165 lines (163 loc) · 4.08 KB
/
VPC2R53.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
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
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Cloud formation example to create VPC, IGW, public subnet, routetable,sg, ASg,Lc, elb & Route53
Parameters:
AvailabilityZone:
Type: String
Default: us-east-1a
ImageId:
Type: String
Default: ami-8c1be5f6
userData:
Type: String
Default: |
#!/bin/bash
yum install httpd -y
yum update -y
service httpd start
chkconfig httpd on
echo "<html><h1>Hello VPC instances!</h1></html>" > /var/www/html/index.html
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: demo-vpc
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties: {}
VPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId:
Ref: InternetGateway
VpcId:
Ref: VPC
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Ref: AvailabilityZone
CidrBlock: 10.0.0.0/24
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: Public
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: Public
OutboundConnectionRoute:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId:
Ref: InternetGateway
RouteTableId:
Ref: PublicRouteTable
PublicSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId:
Ref: PublicRouteTable
SubnetId:
Ref: PublicSubnet
WebServerSG:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId:
Ref: VPC
GroupDescription: Allows inbound http traffic
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: tcp
ToPort: 80
Tags:
- Key: Name
Value: http
EC2SG:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId:
Ref: VPC
GroupDescription: Allows inbound http traffic
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: tcp
ToPort: 80
- CidrIp: 0.0.0.0/0
FromPort: 22
IpProtocol: tcp
ToPort: 22
- CidrIp: 0.0.0.0/0
FromPort: 443
IpProtocol: tcp
ToPort: 443
Tags:
- Key: Name
Value: EC2SG
LoadBalancer:
Type: AWS::ElasticLoadBalancing::LoadBalancer
Properties:
LoadBalancerName: LoadBalancer
Listeners:
- InstancePort: 80
InstanceProtocol: HTTP
LoadBalancerPort: 80
Protocol: HTTP
Scheme: internet-facing
SecurityGroups:
- Ref: WebServerSG
Subnets:
- Ref: PublicSubnet
AppLaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
AssociatePublicIpAddress: true
ImageId:
Ref: ImageId
InstanceType: t2.micro
UserData:
"Fn::Base64": !Ref userData
SecurityGroups:
- Ref: EC2SG
DependsOn: VPCGatewayAttachment
AppASG:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AvailabilityZones:
- Ref: AvailabilityZone
DesiredCapacity: 1
LaunchConfigurationName:
Ref: AppLaunchConfiguration
LoadBalancerNames:
- Ref: LoadBalancer
MaxSize: 2
MinSize: 1
VPCZoneIdentifier:
- Ref: PublicSubnet
UpdatePolicy:
AutoScalingRollingUpdate:
MinInstancesInService: 1
ROute53:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneName: myrama.net.
Comment: Zone apex alias targeted to LoadBalancer.
RecordSets:
- Name: test.myrama.net.
Type: A
AliasTarget:
HostedZoneId: !GetAtt LoadBalancer.CanonicalHostedZoneNameID
DNSName: !GetAtt LoadBalancer.DNSName