-
Notifications
You must be signed in to change notification settings - Fork 0
/
elb.yaml
76 lines (68 loc) · 2.02 KB
/
elb.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
AWSTemplateFormatVersion: 2010-09-09
Description: Hands-on template for ALB
#------------------------------------------------------
# AWS CLIの実行の仕方
# aws cloudformation create-stack --stack-name handson-cfn-elb --template-body file://elb.yml
#------------------------------------------------------
# スタック名
# handson-cfn-elb
Parameters:
VPCStack:
Type: String
Default: handson-cfn
EC2Stack:
Type: String
Default: handson-cfn-ec2
#------------------------------------------------------
# ELB
#------------------------------------------------------
Resources:
FrontLB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: !Ref AWS::StackName
Subnets:
- Fn::ImportValue: !Sub ${VPCStack}-PublicSubnet1
- Fn::ImportValue: !Sub ${VPCStack}-PublicSubnet2
SecurityGroups:
- !Ref SecurityGroupLB
FrontLBListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref FrontLB
Port: 80
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref FrontLBTargetGroup
FrontLBTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: !Sub ${AWS::StackName}-tg
VpcId:
Fn::ImportValue: !Sub ${VPCStack}-VPCID
Port: 80
Protocol: HTTP
HealthCheckPath: /.check_alive
Targets:
- Id:
Fn::ImportValue: !Sub ${EC2Stack}-EC2WebServer01
SecurityGroupLB:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Ref AWS::StackName
VpcId:
Fn::ImportValue: !Sub ${VPCStack}-VPCID
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
#------------------------------------------------------
# Outputsセクション
#------------------------------------------------------
Outputs:
FrontLBEndpoint:
Value: !GetAtt FrontLB.DNSName
Export:
Name: !Sub ${AWS::StackName}-Endpoint