-
Notifications
You must be signed in to change notification settings - Fork 0
/
webapp.yaml
113 lines (104 loc) · 3.02 KB
/
webapp.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
Parameters:
ProjectName:
Description: Project Name
Type: String
Default: weby
Resources:
EC2LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: !Sub ${ProjectName}-launchTemp
VersionDescription: 1
LaunchTemplateData:
ImageId: ami-0574da719dca65348
InstanceType: t2.micro
KeyName: udakey
SecurityGroupIds:
- Fn::ImportValue:
!Sub ${ProjectName}:WebAppSec
UserData:
Fn::Base64: |
#!/bin/bash
sudo apt-get update -y
sudo apt-get install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2.service
cd /var/www/html
echo "Hello from the other side!" > index.html
WebAppASG:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
LaunchTemplate:
LaunchTemplateId: !Ref EC2LaunchTemplate
Version: !GetAtt EC2LaunchTemplate.LatestVersionNumber
MaxSize: 4
MinSize: 2
DesiredCapacity: 2
VPCZoneIdentifier:
- Fn::ImportValue:
!Sub "${ProjectName}:PrivateSub1"
- Fn::ImportValue:
!Sub "${ProjectName}:PrivateSub2"
TargetGroupARNs:
- !Ref WebAppTargetGroup
Tags:
- Key: project
Value: !Ref ProjectName
PropagateAtLaunch: True
LoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Scheme: internet-facing
SecurityGroups:
- Fn::ImportValue:
!Sub "${ProjectName}:LBSec"
Type: application
Subnets:
- Fn::ImportValue:
!Sub "${ProjectName}:PublicSub1"
- Fn::ImportValue:
!Sub "${ProjectName}:PublicSub2"
ELBListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref WebAppTargetGroup
LoadBalancerArn: !Ref LoadBalancer
Port: 80
Protocol: HTTP
WebAppTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckEnabled: True
HealthCheckIntervalSeconds: 30
HealthCheckPath: /
HealthCheckPort: 80
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 3
IpAddressType: ipv4
Name: webTargetGroup
Port: 80
Protocol: HTTP
TargetType: instance
UnhealthyThresholdCount: 2
VpcId:
Fn::ImportValue:
!Sub "${ProjectName}:VPC"
WebAppScailingPolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AutoScalingGroupName: !Ref WebAppASG
EstimatedInstanceWarmup: 30
PolicyType: TargetTrackingScaling
TargetTrackingConfiguration:
PredefinedMetricSpecification:
PredefinedMetricType: ASGAverageCPUUtilization
TargetValue: 50
Outputs:
LBURL:
Description: Loadbalancer DNS name
Value: !GetAtt LoadBalancer.DNSName
Export:
Name: !Sub "${ProjectName}:LB"