簡體   English   中英

CloudFormation 模板 -> ALB 目標組不支持 http/TCP 協議

[英]CloudFormation template -> ALB target group not supporting http/TCP protocol

所以我有一個創建自動縮放、VPC 和 ELB(經典)的整個堆棧,我試圖用應用程序負載均衡器替換它,我在下面給出了模板位。

所以我面臨的錯誤是

TargetGroup1    CREATE_FAILED

Target type 'alb' is not supported for target groups with HTTP protocol (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: InvalidConfigurationRequest; Request ID: 29cdf7fd-5b12-4ef6-b812-baee840038ff; Proxy: null)

在“AWS::ElasticLoadBalancingV2::TargetGroup”中,我已將協議:HTTP 更改為協議:tcp,如控制台配置中所示的 alb 類型

注意:StackALB 已創建,ALBlistener 尚未創建

    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    Properties:
      Name: StackALB
      Scheme: internet-facing
      SecurityGroups:
        - !Ref InstanceSecurityGroup
      Subnets:
        - !Ref PublicSubnet0
        - !Ref PrivateSubnet0
      Type: application
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 421548e4-192c-4a89-b236-41eb956dc7f3
  TargetGroup1:
    Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
    Properties:
      TargetType: alb
      Targets:
        - Id: !Ref StackALB
      Port: 80
      Protocol: HTTP
      VpcId: !Ref VPC
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 3517f34b-2be3-49d1-a3b6-8db672475be2
  ALBlistener:
    Type: 'AWS::ElasticLoadBalancingV2::Listener'
    Properties:
      DefaultActions:
        - Type: forward
          ForwardConfig:
            TargetGroups:
              - TargetGroupArn: !Ref TargetGroup1
                Weight: 1
      LoadBalancerArn: !Ref StackALB
      Port: 80
      Protocol: HTTP
    Metadata:
      'AWS::CloudFormation::Designer':
        id: d0c17083-9c13-48c2-8e13-948b2a096e71

參考的整個模板

AWSTemplateFormatVersion: 2010-09-09
Metadata:
  License: Apache-2.0
  'AWS::CloudFormation::Designer':
    9b07d92a-36f9-4ca7-b4f9-40753f1378b0:
      size:
        width: 60
        height: 60
      position:
        x: 670
        'y': 270
      z: 2
      parent: 702fe9ac-3a89-4063-a715-aaea1b5400fd
      embeds: []
    10cee608-9eec-488a-8b24-b541623d0fe1:
      size:
        width: 60
        height: 60
      position:
        x: 730
        'y': 660
      z: 1
      embeds: []
    f0410b0f-a2df-48b6-9788-39a256d08eae:
      size:
        width: 150
        height: 150
      position:
        x: 60
        'y': 660
      z: 1
      embeds: []
    702fe9ac-3a89-4063-a715-aaea1b5400fd:
      size:
        width: 240
        height: 240
      position:
        x: 570
        'y': 120
      z: 1
      embeds:
        - 9b07d92a-36f9-4ca7-b4f9-40753f1378b0
        - 58ad94a5-9d1f-4e1f-ae00-b9069c760c77
    a3c175b4-faf1-4eac-9242-941a6a932a70:
      size:
        width: 150
        height: 150
      position:
        x: 660
        'y': 90
      z: 1
      embeds: []
    db29192c-fd22-4c87-94b1-d1e41208d236:
      size:
        width: 60
        height: 60
      position:
        x: 770
        'y': 540
      z: 1
      embeds: []
    925feb40-cd97-4e4e-b56f-87b10aabc2ab:
      size:
        width: 60
        height: 60
      position:
        x: 320
        'y': 620
      z: 1
      embeds: []
    608b0bd0-06e9-4c6a-91f3-129e176fa8ff:
      size:
        width: 240
        height: 240
      position:
        x: 880
        'y': 510
      z: 1
      embeds:
        - 05eb18d9-0497-41c1-8c12-edf0a9caed16
    7e0c544e-910b-4641-a19c-68ee82898135:
      source:
        id: f0410b0f-a2df-48b6-9788-39a256d08eae
      target:
        id: 10cee608-9eec-488a-8b24-b541623d0fe1
      z: 1
    05eb18d9-0497-41c1-8c12-edf0a9caed16:
      size:
        width: 60
        height: 60
      position:
        x: 910
        'y': 570
      z: 2
      parent: 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
      embeds: []
      isassociatedwith:
        - 10cee608-9eec-488a-8b24-b541623d0fe1
      iscontainedinside:
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
        - 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
      dependson:
        - 7e0c544e-910b-4641-a19c-68ee82898135
    e0179fd8-f057-4e90-8a5f-a446819a41d4:
      size:
        width: 150
        height: 150
      position:
        x: 480
        'y': 390
      z: 1
      embeds: []
    5f524e69-2fcb-4c51-a191-e6c5f3df3e34:
      size:
        width: 150
        height: 150
      position:
        x: 210
        'y': 390
      z: 1
      embeds: []
    52a67d2e-df44-4440-b3ef-4afe0984de88:
      source:
        id: a3c175b4-faf1-4eac-9242-941a6a932a70
      target:
        id: 5f524e69-2fcb-4c51-a191-e6c5f3df3e34
      z: 1
    3f2064e8-d473-4556-b09f-952c8da429e6:
      size:
        width: 240
        height: 240
      position:
        x: 300
        'y': 60
      z: 1
      embeds:
        - c1ff09b0-2e8e-4521-8154-3b94b5a600f8
    ae8384a4-37c1-4865-8b97-2745a3a8b3e1:
      size:
        width: 60
        height: 60
      position:
        x: 510
        'y': 660
      z: 1
      embeds: []
    58ad94a5-9d1f-4e1f-ae00-b9069c760c77:
      size:
        width: 60
        height: 60
      position:
        x: 600
        'y': 180
      z: 2
      parent: 702fe9ac-3a89-4063-a715-aaea1b5400fd
      embeds: []
      isassociatedwith:
        - ae8384a4-37c1-4865-8b97-2745a3a8b3e1
      iscontainedinside:
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
        - 702fe9ac-3a89-4063-a715-aaea1b5400fd
    04996b8c-bca2-4427-84e1-a7a83896a064:
      source:
        id: a3c175b4-faf1-4eac-9242-941a6a932a70
      target:
        id: 3f2064e8-d473-4556-b09f-952c8da429e6
      z: 1
    abf07dea-ed6c-4cf6-9a5b-f0f9c7c2a786:
      size:
        width: 60
        height: 60
      position:
        x: 970
        'y': 100
      z: 1
      embeds: []
    ce9c0357-7785-4df9-8a35-90a70b25503c:
      size:
        width: 60
        height: 60
      position:
        x: 840
        'y': 210
      z: 1
      embeds: []
    d34ee484-081e-4e35-9cf3-3b17666df818:
      size:
        width: 60
        height: 60
      position:
        x: 840
        'y': 330
      z: 1
      embeds: []
      iscontainedinside:
        - f0410b0f-a2df-48b6-9788-39a256d08eae
    e5ce1987-9fc2-4413-9f04-eeacb78bdffc:
      size:
        width: 60
        height: 60
      position:
        x: 1050
        'y': 270
      z: 1
      embeds: []
    84837bdc-620c-4ff2-8efb-2bf7173a7096:
      size:
        width: 60
        height: 60
      position:
        x: 920
        'y': 410
      z: 1
      embeds: []
      isassociatedwith:
        - e5ce1987-9fc2-4413-9f04-eeacb78bdffc
        - 4b12ea4b-e211-4f55-a823-4da7113ce154
      iscontainedinside:
        - e0179fd8-f057-4e90-8a5f-a446819a41d4
      dependson:
        - f0410b0f-a2df-48b6-9788-39a256d08eae
    c1ff09b0-2e8e-4521-8154-3b94b5a600f8:
      size:
        width: 60
        height: 60
      position:
        x: 330
        'y': 120
      z: 2
      parent: 3f2064e8-d473-4556-b09f-952c8da429e6
      embeds: []
      iscontainedinside:
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
        - 3f2064e8-d473-4556-b09f-952c8da429e6
    44f9157c-7abe-48e1-b19a-9b5066a87acb:
      size:
        width: 60
        height: 60
      position:
        x: -20
        'y': 170
      z: 0
      embeds: []
    421548e4-192c-4a89-b236-41eb956dc7f3:
      size:
        width: 60
        height: 60
      position:
        x: 180
        'y': 230
      z: 0
      embeds: []
      isassociatedwith:
        - d34ee484-081e-4e35-9cf3-3b17666df818
      iscontainedinside:
        - 5f524e69-2fcb-4c51-a191-e6c5f3df3e34
        - 5f524e69-2fcb-4c51-a191-e6c5f3df3e34
        - e0179fd8-f057-4e90-8a5f-a446819a41d4
        - 3f2064e8-d473-4556-b09f-952c8da429e6
    3517f34b-2be3-49d1-a3b6-8db672475be2:
      size:
        width: 60
        height: 60
      position:
        x: 30
        'y': 430
      z: 0
      embeds: []
      iscontainedinside:
        - f0410b0f-a2df-48b6-9788-39a256d08eae
      dependson:
        - d0c17083-9c13-48c2-8e13-948b2a096e71
    d0c17083-9c13-48c2-8e13-948b2a096e71:
      size:
        width: 60
        height: 60
      position:
        x: 30
        'y': 300
      z: 0
      embeds: []
Description: 'entire VPC and EC2,ELB config'
Parameters:
  InstanceType:
    Description: WebServer EC2 instance type
    Type: String
    Default: t2.micro
    AllowedValues:
      - t1.micro
      - t2.nano
      - t2.micro
      - t2.small
      - t2.medium
      - t2.large
      - m1.small
      - m1.medium
      - m1.large
      - m1.xlarge
      - m2.xlarge
      - m2.2xlarge
      - m2.4xlarge
      - m3.medium
      - m3.large
      - m3.xlarge
      - m3.2xlarge
      - m4.large
      - m4.xlarge
      - m4.2xlarge
      - m4.4xlarge
      - m4.10xlarge
      - c1.medium
      - c1.xlarge
      - c3.large
      - c3.xlarge
      - c3.2xlarge
      - c3.4xlarge
      - c3.8xlarge
      - c4.large
      - c4.xlarge
      - c4.2xlarge
      - c4.4xlarge
      - c4.8xlarge
      - g2.2xlarge
      - g2.8xlarge
      - r3.large
      - r3.xlarge
      - r3.2xlarge
      - r3.4xlarge
      - r3.8xlarge
      - i2.xlarge
      - i2.2xlarge
      - i2.4xlarge
      - i2.8xlarge
      - d2.xlarge
      - d2.2xlarge
      - d2.4xlarge
      - d2.8xlarge
      - hi1.4xlarge
      - hs1.8xlarge
      - cr1.8xlarge
      - cc2.8xlarge
      - cg1.4xlarge
    ConstraintDescription: must be a valid EC2 instance type.
  KeyName:
    Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
    Type: 'AWS::EC2::KeyPair::KeyName'
    ConstraintDescription: must be the name of an existing EC2 KeyPair.
  SSHLocation:
    Description: The IP address range that can be used to SSH to the EC2 instances
    Type: String
    MinLength: '9'
    MaxLength: '18'
    Default: 0.0.0.0/0
    AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
    ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
  VPCName:
    Description: The name of the VPC being created.
    Type: String
    Default: VPC Public and Private with NAT
Mappings:
  ##removed for char limit(used wordpress ami##
Resources:
  VPC:
    Type: 'AWS::EC2::VPC'
    Properties:
      EnableDnsSupport: 'true'
      EnableDnsHostnames: 'true'
      CidrBlock: !FindInMap 
        - SubnetConfig
        - VPC
        - CIDR
      Tags:
        - Key: Application
          Value: !Ref 'AWS::StackName'
        - Key: Network
          Value: Public
        - Key: Name
          Value: !Ref VPCName
    Metadata:
      'AWS::CloudFormation::Designer':
        id: f0410b0f-a2df-48b6-9788-39a256d08eae
  PublicSubnet0:
    Type: 'AWS::EC2::Subnet'
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: us-east-1b
      CidrBlock: !FindInMap 
        - SubnetConfig
        - Public0
        - CIDR
      MapPublicIpOnLaunch: 'true'
      Tags:
        - Key: Application
          Value: !Ref 'AWS::StackName'
        - Key: Network
          Value: Public
        - Key: Name
          Value: !Join 
            - ''
            - - !Ref VPCName
              - '-public-'
              - !Select 
                - 0
                - !FindInMap 
                  - AZRegions
                  - !Ref 'AWS::Region'
                  - AZs
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 3f2064e8-d473-4556-b09f-952c8da429e6
  PublicSubnet1:
    Type: 'AWS::EC2::Subnet'
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: us-east-1b
      CidrBlock: !FindInMap 
        - SubnetConfig
        - Public1
        - CIDR
      MapPublicIpOnLaunch: 'true'
      Tags:
        - Key: Application
          Value: !Ref 'AWS::StackName'
        - Key: Network
          Value: Public
        - Key: Name
          Value: !Join 
            - ''
            - - !Ref VPCName
              - '-public-'
              - !Select 
                - 1
                - !FindInMap 
                  - AZRegions
                  - !Ref 'AWS::Region'
                  - AZs
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 5f524e69-2fcb-4c51-a191-e6c5f3df3e34
  PrivateSubnet0:
    Type: 'AWS::EC2::Subnet'
    Properties:
      VpcId: !Ref VPC
      AvailabilityZone: us-east-1a
      CidrBlock: !FindInMap 
        - SubnetConfig
        - Private0
        - CIDR
      Tags:
        - Key: Application
          Value: !Ref 'AWS::StackName'
        - Key: Network
          Value: Private
        - Key: Name
          Value: !Join 
            - ''
            - - !Ref VPCName
              - '-private-'
              - !Select 
                - 0
                - !FindInMap 
                  - AZRegions
                  - !Ref 'AWS::Region'
                  - AZs
    Metadata:
      'AWS::CloudFormation::Designer':
        id: e0179fd8-f057-4e90-8a5f-a446819a41d4
  InternetGateway:
    Type: 'AWS::EC2::InternetGateway'
    Properties:
      Tags:
        - Key: Application
          Value: !Ref 'AWS::StackName'
        - Key: Network
          Value: Public
        - Key: Name
          Value: !Join 
            - ''
            - - !Ref VPCName
              - '-IGW'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 10cee608-9eec-488a-8b24-b541623d0fe1
  GatewayToInternet:
    Type: 'AWS::EC2::VPCGatewayAttachment'
    Properties:
      VpcId: !Ref VPC
      InternetGatewayId: !Ref InternetGateway
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 7e0c544e-910b-4641-a19c-68ee82898135
  PublicRouteTable:
    Type: 'AWS::EC2::RouteTable'
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Application
          Value: !Ref 'AWS::StackName'
        - Key: Network
          Value: Public
        - Key: Name
          Value: !Join 
            - ''
            - - !Ref VPCName
              - '-public-route-table'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 608b0bd0-06e9-4c6a-91f3-129e176fa8ff
  PublicRoute:
    Type: 'AWS::EC2::Route'
    DependsOn: GatewayToInternet
    Properties:
      RouteTableId: !Ref PublicRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref InternetGateway
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 05eb18d9-0497-41c1-8c12-edf0a9caed16
  PublicSubnetRouteTableAssociation0:
    Type: 'AWS::EC2::SubnetRouteTableAssociation'
    Properties:
      SubnetId: !Ref PublicSubnet0
      RouteTableId: !Ref PublicRouteTable
  PublicSubnetRouteTableAssociation1:
    Type: 'AWS::EC2::SubnetRouteTableAssociation'
    Properties:
      SubnetId: !Ref PublicSubnet1
      RouteTableId: !Ref PublicRouteTable
  PublicNetworkAcl:
    Type: 'AWS::EC2::NetworkAcl'
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Application
          Value: !Ref 'AWS::StackName'
        - Key: Network
          Value: Public
        - Key: Name
          Value: !Join 
            - ''
            - - !Ref VPCName
              - '-public-nacl'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: a3c175b4-faf1-4eac-9242-941a6a932a70
  InboundHTTPPublicNetworkAclEntry:
    Type: 'AWS::EC2::NetworkAclEntry'
    Properties:
      NetworkAclId: !Ref PublicNetworkAcl
      RuleNumber: '100'
      Protocol: '-1'
      RuleAction: allow
      Egress: 'false'
      CidrBlock: 0.0.0.0/0
      PortRange:
        From: '0'
        To: '65535'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 925feb40-cd97-4e4e-b56f-87b10aabc2ab
  OutboundPublicNetworkAclEntry:
    Type: 'AWS::EC2::NetworkAclEntry'
    Properties:
      NetworkAclId: !Ref PublicNetworkAcl
      RuleNumber: '100'
      Protocol: '-1'
      RuleAction: allow
      Egress: 'true'
      CidrBlock: 0.0.0.0/0
      PortRange:
        From: '0'
        To: '65535'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: db29192c-fd22-4c87-94b1-d1e41208d236
  PublicSubnetNetworkAclAssociation0:
    Type: 'AWS::EC2::SubnetNetworkAclAssociation'
    Properties:
      SubnetId: !Ref PublicSubnet0
      NetworkAclId: !Ref PublicNetworkAcl
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 04996b8c-bca2-4427-84e1-a7a83896a064
  PublicSubnetNetworkAclAssociation1:
    Type: 'AWS::EC2::SubnetNetworkAclAssociation'
    Properties:
      SubnetId: !Ref PublicSubnet1
      NetworkAclId: !Ref PublicNetworkAcl
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 52a67d2e-df44-4440-b3ef-4afe0984de88
  ElasticIP0:
    Type: 'AWS::EC2::EIP'
    Properties:
      Domain: vpc
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 9b07d92a-36f9-4ca7-b4f9-40753f1378b0
  NATGateway0:
    Type: 'AWS::EC2::NatGateway'
    Properties:
      AllocationId: !GetAtt 
        - ElasticIP0
        - AllocationId
      SubnetId: !Ref PublicSubnet0
    Metadata:
      'AWS::CloudFormation::Designer':
        id: ae8384a4-37c1-4865-8b97-2745a3a8b3e1
  PrivateRouteTable0:
    Type: 'AWS::EC2::RouteTable'
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: !Join 
            - ''
            - - !Ref VPCName
              - '-private-route-table-0'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 702fe9ac-3a89-4063-a715-aaea1b5400fd
  PrivateRouteToInternet0:
    Type: 'AWS::EC2::Route'
    Properties:
      RouteTableId: !Ref PrivateRouteTable0
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId: !Ref NATGateway0
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 58ad94a5-9d1f-4e1f-ae00-b9069c760c77
  PrivateSubnetRouteTableAssociation0:
    Type: 'AWS::EC2::SubnetRouteTableAssociation'
    Properties:
      SubnetId: !Ref PrivateSubnet0
      RouteTableId: !Ref PrivateRouteTable0
  WebServerGroup:
    Type: 'AWS::AutoScaling::AutoScalingGroup'
    Properties:
      VPCZoneIdentifier:
        - !Ref PrivateSubnet0
      AvailabilityZones:
        - us-east-1a
      LaunchConfigurationName: !Ref LaunchConfig
      MinSize: '2'
      MaxSize: '4'
      LoadBalancerNames:
        - !Ref StackALB
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 84837bdc-620c-4ff2-8efb-2bf7173a7096
    DependsOn:
      - VPC
  LaunchConfig:
    Type: 'AWS::AutoScaling::LaunchConfiguration'
    Metadata:
      'AWS::CloudFormation::Init':
        verify_instance_health:
          commands:
            ELBHealthCheck:
              command: !Sub >-
                until [ "$state" == "\"InService\"" ]; do state=$(aws --region
                ${AWS::Region} elb describe-instance-health --load-balancer-name
                ${StackALB} --instances $(curl -s
                http://169.254.169.254/latest/meta-data/instance-id) --query
                InstanceStates[0].State); sleep 10; done
      'AWS::CloudFormation::Designer':
        id: e5ce1987-9fc2-4413-9f04-eeacb78bdffc
    Properties:
      KeyName: !Ref KeyName
      ImageId: !FindInMap 
        - AWSRegionArch2AMI
        - !Ref 'AWS::Region'
        - !FindInMap 
          - AWSInstanceType2Arch
          - !Ref InstanceType
          - Arch
      InstanceType: !Ref InstanceType
      SecurityGroups:
        - !Ref InstanceSecurityGroup
      IamInstanceProfile: !Ref WebServerInstanceProfile
  InstanceSecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupDescription: Enable SSH access and HTTP access on the configured port
      VpcId: !Ref VPC
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '22'
          ToPort: '22'
          CidrIp: !Ref SSHLocation
        - IpProtocol: tcp
          FromPort: '80'
          ToPort: '80'
          CidrIp: 0.0.0.0/0
    Metadata:
      'AWS::CloudFormation::Designer':
        id: d34ee484-081e-4e35-9cf3-3b17666df818
  WebServerInstanceProfile:
    Type: 'AWS::IAM::InstanceProfile'
    Properties:
      Path: /
      Roles:
        - !Ref DescribeHealthRole
    Metadata:
      'AWS::CloudFormation::Designer':
        id: ce9c0357-7785-4df9-8a35-90a70b25503c
  DescribeHealthRole:
    Type: 'AWS::IAM::Role'
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - 'sts:AssumeRole'
      Path: /
      Policies:
        - PolicyName: describe-instance-health-policy
          PolicyDocument:
            Statement:
              - Effect: Allow
                Action:
                  - 'elasticloadbalancing:DescribeInstanceHealth'
                  - 'elasticloadbalancing:DeregisterTargets'
                  - 'elasticloadbalancing:RegisterTargets'
                  - 'elasticloadbalancing:DeregisterInstancesFromLoadBalancer'
                  - 'elasticloadbalancing:RegisterInstancesWithLoadBalancer'
                  - 'ec2:Describe*'
                  - 'ec2:AuthorizeSecurityGroupIngress'
                Resource: '*'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: abf07dea-ed6c-4cf6-9a5b-f0f9c7c2a786
  Bastionins:
    Type: 'AWS::EC2::Instance'
    Properties:
      ImageId: ami-052efd3df9dad4825
      InstanceType: t2.micro
      KeyName: !Ref KeyName
      NetworkInterfaces:
        - AssociatePublicIpAddress: 'true'
          DeviceIndex: '0'
          GroupSet:
            - !Ref InstanceSecurityGroup
          SubnetId: !Ref PublicSubnet0
    Metadata:
      'AWS::CloudFormation::Designer':
        id: c1ff09b0-2e8e-4521-8154-3b94b5a600f8
  R53HC46WDD:
    Type: 'AWS::Route53::HealthCheck'
    Properties:
      HealthCheckConfig:
        Type: HTTP
        FullyQualifiedDomainName: !GetAtt 
          - StackALB
          - DNSName
        RequestInterval: '30'
        FailureThreshold: '5'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 44f9157c-7abe-48e1-b19a-9b5066a87acb
  StackALB:
    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    Properties:
      Name: StackALB
      Scheme: internet-facing
      SecurityGroups:
        - !Ref InstanceSecurityGroup
      Subnets:
        - !Ref PublicSubnet0
        - !Ref PrivateSubnet0
      Type: application
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 421548e4-192c-4a89-b236-41eb956dc7f3
  TargetGroup1:
    Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
    Properties:
      TargetType: alb
      Targets:
        - Id: !Ref StackALB
      Port: 80
      Protocol: HTTP
      VpcId: !Ref VPC
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 3517f34b-2be3-49d1-a3b6-8db672475be2
  ALBlistener:
    Type: 'AWS::ElasticLoadBalancingV2::Listener'
    Properties:
      DefaultActions:
        - Type: forward
          ForwardConfig:
            TargetGroups:
              - TargetGroupArn: !Ref TargetGroup1
                Weight: 1
      LoadBalancerArn: !Ref StackALB
      Port: 80
      Protocol: HTTP
    Metadata:
      'AWS::CloudFormation::Designer':
        id: d0c17083-9c13-48c2-8e13-948b2a096e71

alb TargetType支持 NLB不支持 ALB 因此,如果您想在目標組中使用alb作為目標,則必須更改設置以使用 NLB。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM