Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
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
Tags
more
Archives
Today
Total
관리 메뉴

JINIers

cloudformaiton 이용 네트워크 구성하기(LB 생성) 본문

AWS/이것저것

cloudformaiton 이용 네트워크 구성하기(LB 생성)

JINIers 2024. 3. 29. 09:43

LB랑 target group을 생성해주고 outputs으로 내보낸다.

네트워크 구성 순서

 


이 전 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'

 

2. create-LB.yaml
0.00MB

Comments