amazon-web-services - 应用程序负载均衡器 - 运行状况检查失败,代码为 : [301]

标签 amazon-web-services aws-cloudformation amazon-ecs aws-application-load-balancer

您好,我正在使用 cloudformation 创建 ecs 集群,由于我的实例运行状况不佳,我在配置任务和应用程序负载均衡器端口时遇到了问题。我可能给出了错误的端口,请指出错误。我只在我认为有错误的地方附加模板。

任务模板:

---
AWSTemplateFormatVersion: 2010-09-09 
Parameters:
    ExRole:
      Type: String
    
    RDS:
      Type: String
 
    Dbname:
      Type: String
    
    dbpassword:
      Type: String

    containerName:
      Type: String
    
    taskFamily:
      Type: String


Resources:
    Task:
        Type: AWS::ECS::TaskDefinition
        Properties:
            Family: !Ref taskFamily
            Cpu: 1 vCPU
            ExecutionRoleArn: !Ref ExRole
            Memory: 1 GB
            NetworkMode: bridge
            RequiresCompatibilities:
                - EC2
            TaskRoleArn: !Ref ExRole
            ContainerDefinitions: 
              - Essential: true
                Image: wordpress:latest
                Name: !Ref containerName
                PortMappings:  
                  - ContainerPort: 80
                    HostPort: 0
                    Protocol: tcp 
                Environment:
                  - Name: WORDPRESS_DB_HOST
                    Value: !Ref RDS 
                  - Name: WORDPRESS_DB_USER
                    Value: !Ref Dbname 
                  - Name: WORDPRESS_DB_PASSWORD
                    Value: !Ref dbpassword
                  - Name: WORDPRESS_DB_NAME
                    Value: !Ref Dbname
    
Outputs:
  Task:
    Description: Contains all the task specifications
    Value: !Ref Task
    Export:
      Name: !Sub "${AWS::StackName}-Task"

应用程序负载均衡器:

---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
    
    SubnetA:
      Type: String
    
    SubnetB:
      Type: String
    
    VpcID:
      Type: String
      
    Env:
      Type: String

Resources:
    Albsg:
        Type: AWS::EC2::SecurityGroup
        Properties:
            GroupName: !Sub "albsg-${Env}"
            VpcId: !Ref VpcID
            SecurityGroupIngress:
                - IpProtocol: tcp
                  FromPort: 80
                  ToPort: 80
                  CidrIp: 0.0.0.0/0
                  Description: For traffic from Internet
            GroupDescription: Security Group for demo server
    Alb:
        Type: AWS::ElasticLoadBalancingV2::LoadBalancer
        Properties: 
            IpAddressType: ipv4
            Name: !Sub "Alb-${Env}"
            Scheme: internet-facing
            SecurityGroups: 
                - !Ref Albsg
            Subnets:
                - Ref: "SubnetA"
                - Ref: "SubnetB"
            Type: application
    DefaultTargetGroup:
        Type: AWS::ElasticLoadBalancingV2::TargetGroup
        DependsOn: Alb
        Properties:
            Name: !Sub "Albtg-${Env}"
            VpcId: !Ref VpcID
            Port: 80
            Protocol: HTTP
            Matcher:
              HttpCode: 302
    LoadBalancerListener:
        Type: AWS::ElasticLoadBalancingV2::Listener
        Properties:
            LoadBalancerArn: !Ref Alb
            Port: 80
            Protocol: HTTP
            DefaultActions:
                - Type: forward
                  TargetGroupArn: !Ref DefaultTargetGroup
Outputs:
  Albsg:
    Description: security group for application load balancer
    Value: !Ref Albsg
    Export:
        Name: !Sub "${AWS::StackName}-Albsg"
  Alb:
    Description: application load balancer
    Value: !Ref Alb
    Export:
      Name: !Sub "${AWS::StackName}-Alb"
  DefaultTargetGroup:
    Description: Default Target Group
    Value: !Ref DefaultTargetGroup
    Export:
      Name: !Sub "${AWS::StackName}-DefaultTargetGroup"       

我的实例处于耗尽状态并且运行状况不佳,请参阅此屏幕截图: enter image description here

最佳答案

301 表示访问目标健康检查路径上的 ECS 主机正在执行重定向(因此是 301)。要修复此问题,请将运行状况检查中的路径更新为不会重定向的路径,或者更新运行状况检查状态代码以包含 301。这可以作为单个状态代码 (301) 或范围 (200-399) 来完成。

关于amazon-web-services - 应用程序负载均衡器 - 运行状况检查失败,代码为 : [301],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63288969/

相关文章:

docker - 1天后,AWS ECS启动容器的速度非常慢

aws-cloudformation - 使用 AWS CDK 为 AWS API 网关启用 CORS

json - 使用输出部分创建 Cloudformation 堆栈时无输出

amazon-web-services - 用于创建 ECS 服务的 Cloudformation 模板卡在 CREATE_IN_PROGRESS 中

amazon-web-services - 域 + AWS EC2 : How to make www. mydomain.com 指向我的 EC2 服务器吗?

java - 如何使用 SDK 设置 ecs 服务的自动伸缩策略的最小和最大任务?

docker - 引用在同一个 ECS 集群中运行的另一个服务/任务

python - EMR 笔记本不存在 IAM 角色

mysql - AWS Aurora - 无法连接到 aws aurora 数据库

amazon-web-services - Amazon connect 实例拒绝连接 | 'X-Frame-Options' 至 'sameorigin'