-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdevopsgirls-wordpress.yaml
146 lines (138 loc) · 4.42 KB
/
devopsgirls-wordpress.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
AWSTemplateFormatVersion: '2010-09-09'
Description: DevOps Girls Cloudformation Stack
Parameters:
InstanceType:
Description: WebServer EC2 instance type
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- t2.small
- t2.medium
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.
DevopsGirlsUser:
Description: Pin Yin of your name
Type: String
MinLength: '1'
MaxLength: '64'
ConstraintDescription: must begin with a letter and contain only alphanumeric
characters.
Mappings:
AWSInstanceType2Arch:
t2.micro:
Arch: HVM64
t2.small:
Arch: HVM64
t2.medium:
Arch: HVM64
AWSRegionArch2AMI:
ap-southeast-1:
HVM64: ami-01da99628f381e50a
Resources:
ElasticLoadBalancer:
Type: AWS::ElasticLoadBalancing::LoadBalancer
Properties:
AvailabilityZones: !GetAZs ''
SecurityGroups:
- !GetAtt 'ElasticLoadBalancerSecurityGroup.GroupId'
CrossZone: 'true'
LBCookieStickinessPolicy:
- PolicyName: CookieBasedPolicy
CookieExpirationPeriod: '30'
Listeners:
- LoadBalancerPort: '80'
InstancePort: '80'
Protocol: HTTP
PolicyNames:
- CookieBasedPolicy
HealthCheck:
Target: TCP:80
HealthyThreshold: '2'
UnhealthyThreshold: '5'
Interval: '10'
Timeout: '5'
WebServerSecurityGroup:
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'
SourceSecurityGroupOwnerId: !GetAtt 'ElasticLoadBalancer.SourceSecurityGroup.OwnerAlias'
SourceSecurityGroupId: !GetAtt 'ElasticLoadBalancerSecurityGroup.GroupId'
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref 'SSHLocation'
ElasticLoadBalancerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable HTTP access via port 80 locked down to the load balancer
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
WebServerGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AvailabilityZones: !GetAZs ''
LaunchConfigurationName: !Ref 'LaunchConfig'
MinSize: '1'
MaxSize: '5'
DesiredCapacity: '2'
LoadBalancerNames:
- !Ref 'ElasticLoadBalancer'
CreationPolicy:
ResourceSignal:
Timeout: PT30M
UpdatePolicy:
AutoScalingRollingUpdate:
MinInstancesInService: '1'
MaxBatchSize: '1'
PauseTime: PT30M
WaitOnResourceSignals: 'true'
LaunchConfig:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
ImageId: !FindInMap [AWSRegionArch2AMI, !Ref 'AWS::Region', !FindInMap [AWSInstanceType2Arch,
!Ref 'InstanceType', Arch]]
InstanceType: !Ref 'InstanceType'
SecurityGroups:
- !Ref 'WebServerSecurityGroup'
UserData: !Base64
Fn::Join:
- ''
- - "#!/bin/bash -xe \n"
- "yum update -y aws-cfn-bootstrap \n"
- "aws configure set default.s3.multipart_threshold 64MB \n"
- aws s3 cp s3://devopsgirls-training-xian/
- !Ref 'DevopsGirlsUser'
- "-wordpress.tgz /var/www/wordpress.tgz --no-sign-request \n"
- "yum install httpd php php-mysql -y \n"
- "mkdir -p /var/www/html \n"
- "tar xvfz /var/www/wordpress.tgz -C /var/www/html/ \n"
- "chown -R apache /var/www/html/ \n"
- "service httpd start \n"
- '/opt/aws/bin/cfn-signal -e $? '
- ' --stack '
- !Ref 'AWS::StackName'
- ' --resource WebServerGroup '
- ' --region '
- !Ref 'AWS::Region'
- '
'
Outputs:
WebsiteURL:
Value: !Join ['', ['http://', !GetAtt 'ElasticLoadBalancer.DNSName', /]]
Description: WordPress Website