JINIers
cloudformaiton 이용 네트워크 구성하기(LB 생성) 본문
LB랑 target group을 생성해주고 outputs으로 내보낸다.
네트워크 구성 순서
- vpc 생성
- lb 생성
- autoscaling 생성
이 전 vpc 생성스택에서 리소스를 불러와 타겟하고 타겟 그룹을 생성한다.
타겟그룹만 outputs으로 리소스 내보내기 설정
# create LB.yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: "Create LB and target group"
Parameters:
NetworkStackName:
Description: "Name of an active CloudFormation stack that contains the networking resources, such as the VPC and subnet that will be used in this stack."
Type: String
MinLength: 1
MaxLength: 128
AllowedPattern: '^[a-zA-Z][-a-zA-Z0-9]*$'
Default: vpc
KeyName:
Description: EC2 KeyPair connect instance
Type: AWS::EC2::KeyPair::KeyName
Default: 'test'
AMI:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Description: 'The ID of the AMI.'
Default: /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64
Resources:
# Target group
testTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 30
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 10
HealthyThresholdCount: 5
Matcher:
HttpCode: "200"
Name: testTargetGroup
Port: 80
Protocol: HTTPS
ProtocolVersion: HTTP1
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 20
Targets:
- Id: !ImportValue
Fn::Sub: "${NetworkStackName}-webec2"
VpcId: !ImportValue
Fn::Sub: "${NetworkStackName}-vpcA"
Tags:
- Key: Name
Value: testTargetGroup
- Key: port
Value: 80
# ALB
testALB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
IpAddressType: ipv4
Name: testALB
SecurityGroups:
- Fn::ImportValue:
!Sub ${NetworkStackName}-vpcASG
Subnets:
- Fn::ImportValue:
!Sub ${NetworkStackName}-PublicSubnetA
- Fn::ImportValue:
!Sub ${NetworkStackName}-PublicSubnetB
Tags:
- Key: Name
Value: testALB
Type: application
testALBListener:
Type: AWS::ElasticLoadBalancingV2::Listener
DependsOn:
- testTargetGroup
- testALB
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: testTargetGroup
LoadBalancerArn:
Ref: testALB
Port: 80
Protocol: HTTP
# Outputs
Outputs:
testTargetGroup:
Description: target group
Value: !Ref testTargetGroup
Export:
Name: !Sub '${AWS::StackName}-testTargetGroup'
'AWS > 이것저것' 카테고리의 다른 글
cloudformaiton 이용 네트워크 구성하기(autoscaling 생성) (0) | 2024.03.29 |
---|---|
cloudformaiton 이용 네트워크 구성하기(vpc 생성) (0) | 2024.03.29 |
S3 이용 서버리스 구축 (0) | 2024.03.19 |
create vpc.yaml (0) | 2024.03.14 |
동적 사이트 구축.yaml (0) | 2024.03.14 |
Comments