安全组 ‘ALB-sg’ 无效

huangapple go评论47阅读模式
英文:

Security group 'ALB-sg' is not valid

问题

我通过Cfn创建了一个ALB,但是我遇到了一个错误,错误信息如下:

安全组 'ALB-sg' 无效(服务:AmazonElasticLoadBalancing;状态码:400;错误代码:ValidationError;请求ID:6ec8a268-80cc-4a3e-9477-809dba8a00c7;代理:null)

英文:

I create an ALB by Cfn, but I got the error called

Security group 'ALB-sg' is not valid (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: ValidationError; Request ID: 6ec8a268-80cc-4a3e-9477-809dba8a00c7; Proxy: null)

AWSTemplateFormatVersion: 2010-09-09

Description: AWS CloudFormation Sample Template for creating LoadBalancer

Parameters:
  VPC:
    Description: VPCId of your existing Virtual Private Cloud (VPC)
    Type: String
    Default: vpc-0c9a732125ac08541
  
  PublicSubnet:
    Description: SubnetId of an existing subnet (for the primary network in your Virtual Private Cloud VPC)
    Type: String
    Default: subnet-0787f34404852ceb9

Resources:
  
  ApplicationLoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties: 
      Name: MyApplicationLoadBalancer
      Type: application
      IpAddressType: ipv4
      Scheme: internet-facing
      SecurityGroups: 
        - !Ref Albsg 
      Subnets: 
        - !Ref PublicSubnet
      Tags:
        - Key: Name
          Value: ALB

  HTTPListener:
        Type: "AWS::ElasticLoadBalancingV2::Listener"
        Properties:
            LoadBalancerArn: !Ref ApplicationLoadBalancer
            Port: 80
            Protocol: "HTTP"
            DefaultActions: 
              - Type: forward
                TargetGroupArn: !Ref ALBTargetGroup
  
  
  ALBTargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckIntervalSeconds: 10
      HealthCheckPath: /
      HealthCheckTimeoutSeconds: 5
      HealthyThresholdCount: 2
      Matcher:
        HttpCode: 200,302
      Name: MyWebServers
      Port: 80
      Protocol: HTTP
      TargetType: instance
      UnhealthyThresholdCount: 5
      VpcId: !Ref VPC
      

  Albsg:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupName: ALB-sg
      GroupDescription: Security group for Load balancer
      SecurityGroupIngress:
        - CidrIp: 0.0.0.0/0
          FromPort: '80'
          IpProtocol: tcp
          ToPort: '80'
      Tags:
        - Key: Name 
          Value: ALB_SG

Outputs:
  TargetGroupName:
    Value: !Ref ALBTargetGroup
    Description: Name of Target ARN

I am not sure what else to try. Here is the template I am working with..

答案1

得分: 1

AlbsgSecurityGroupIngress中,FromPortToPort字段必须是整数,而不是字符串。

英文:

In the SecurityGroupIngress of the Albsg, the fields FromPort and ToPort have to be integers, not strings.

答案2

得分: 0

字符串 ALB-sg 只在你的模板中出现一次,所以错误显然就在那里:

GroupName: ALB-sg

我觉得是 - 字符导致的问题。你应该简单地将该值用引号括起来:

GroupName: "ALB-sg"
英文:

The string ALB-sg only appears one place in your template, so that is obviously where the error is:

GroupName: ALB-sg

I'm thinking the - character is throwing it off. You should simply wrap the value in quotes:

GroupName: "ALB-sg"

huangapple
  • 本文由 发表于 2023年3月31日 19:48:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75898190.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定