Description: A sample template
Resources:
MyTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckEnabled: true
HealthCheckIntervalSeconds: 30
HealthCheckPath: /
HealthCheckPort: 80
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 5
Matcher:
HttpCode: 200
Name: MyTargetGroup
Port: 80
Protocol: HTTP
TargetType: instance
UnhealthyThresholdCount: 2
VpcId: 본인 vpc ID
StackELB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
IpAddressType: ipv4
Name: stack-elb
SecurityGroups:
- 본인 보안그룹
Subnets:
- 본인 subnet ID
- 본인 subnet ID
- 본인 subnet ID
- 본인 subnet ID
Type: application
HTTPlistener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
DependsOn:
- MyTargetGroup
- StackELB
Properties:
DefaultActions:
- Type: "forward"
ForwardConfig:
TargetGroups:
- TargetGroupArn: !Ref MyTargetGroup
LoadBalancerArn: !Ref StackELB
Port: 80
Protocol: "HTTP"
MyEC2Template:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: MyEC2Template
LaunchTemplateData:
BlockDeviceMappings:
- DeviceName: "/dev/xvda"
Ebs:
DeleteOnTermination: 'true'
VolumeSize: 8
VolumeType: gp2
ImageId: ami-0ba5cd124d7a79612
InstanceType: t2.micro
KeyName: 본인 키페어
SecurityGroupIds:
- 본인 보안그룹
UserData:
Fn::Base64: !Sub |
#!/bin/bash
apt-get -y update
apt-get install -y apache2
systemctl start apache2
MyASG:
Type: AWS::AutoScaling::AutoScalingGroup
DependsOn:
- MyEC2Template
- StackELB
- MyTargetGroup
Properties:
AutoScalingGroupName: MyASG
LaunchTemplate:
LaunchTemplateName: MyEC2Template
Version: !GetAtt MyEC2Template.LatestVersionNumber
MaxSize: 3
MinSize: 1
TargetGroupARNs:
- !Ref MyTargetGroup
VPCZoneIdentifier:
- 본인 서브넷 아이디
- 본인 서브넷 아이디
- 본인 서브넷 아이디
- 본인 서브넷 아이디
MyCPUPolicy:
Type: AWS::AutoScaling::ScalingPolicy
DependsOn:
- MyASG
Properties:
AutoScalingGroupName: !Ref MyASG
PolicyType: TargetTrackingScaling
TargetTrackingConfiguration:
PredefinedMetricSpecification:
PredefinedMetricType: ASGAverageCPUUtilization
TargetValue: 50