cloudformation中ecs服务的问题:提供的target group有target type instance,与awsvpc网络不兼容

Problems with ecs service in cloudformation: The provided target group has target type instance, which is incompatible with the awsvpc network

我正在用cloudformation创建一个架构,在创建ECS服务的那一刻,出现了我的平衡器实例与awsvpc模式不兼容的错误

我尝试了几种方法,其中 none 对我有用,我看过 aws 指南,这一切都相应地对应,如果可以的话请去解决方案

"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {

    "LoadBalancerQA01": {
        "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
        "Properties": {
           "SecurityGroups": [
                {
                    "Ref": "SecurityGroupPublic01"
                }
            ],
            "Subnets": [
                {
                    "Ref": "SubnetPublicQATestUno"
                },
                {
                    "Ref": "SubnetPublicQATestDos"
                }
            ],
            "Name": "LoadBalancerQA01"
        }
    },
    "LoadBalancerListener": {
      "Type": "AWS::ElasticLoadBalancingV2::Listener",
      "Properties": {
        "DefaultActions": [{
          "Type": "forward",
          "TargetGroupArn": { "Ref": "TargetGroupQA" }
        }],
        "LoadBalancerArn": { "Ref": "LoadBalancerQA01" },
        "Port": 8080,
        "Protocol": "HTTP"
      }
    },
    "TargetGroupQA": {
      "Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
      "Properties": {
        "Name": "TargetGroupQA",
        "Port": 8080,
        "Protocol": "HTTP",
        "VpcId": { "Ref": "VPCQA" }
      },
      "DependsOn": [ "LoadBalancerQA01" ]
    },
    "ClusterQA": {
        "Type": "AWS::ECS::Cluster",
        "Properties": {},
        "DependsOn": [
            "SubnetPrivateQATestUno",
            "SubnetPrivateQATestDos"
        ]
    },
    "TaskQA": {
        "Type": "AWS::ECS::TaskDefinition",
        "Properties": {
            "RequiresCompatibilities": ["FARGATE"],
            "Cpu" : "1024",
            "TaskRoleArn" : "arn:aws:iam::683574420318:role/ecsTaskExecutionRole",
            "ExecutionRoleArn" : "arn:aws:iam::683574420318:role/ecsTaskExecutionRole",
            "Memory": "2048",
            "NetworkMode" : "awsvpc",
             "ContainerDefinitions" : [{ 
                        "Image": "683574420318.dkr.ecr.us-west-1.amazonaws.com/mto:latest",
                        "Cpu": "1024",
                        "Memory": "2048",  
                        "Name":"ContenedorName",
                        "PortMappings":[{ "ContainerPort": 8080,"HostPort": 8080}]

            }]
        }
    },
    "ServiceQA": {
      "Type": "AWS::ECS::Service",
      "DependsOn": [ "LoadBalancerQA01" ],
      "Properties" : {
        "NetworkConfiguration" : {
              "AwsvpcConfiguration" : {
              "AssignPublicIp" : "ENABLED",
              "SecurityGroups" : [
                {
                    "Ref": "SecurityGroupPublic01"
                }
            ],"Subnets": [
                {
                    "Ref": "SubnetPublicQATestUno"
                },
                {
                    "Ref": "SubnetPublicQATestDos"
                }
            ]}
         },
        "Cluster": { "Ref": "ClusterQA" },
        "DesiredCount": "1",
        "LoadBalancers": [
          {
            "ContainerName": "ContenedorName",
            "ContainerPort": 8080,
            "TargetGroupArn": { "Ref": "TargetGroupQA" }
          }
        ],
        "TaskDefinition" : {"Ref":"TaskQA"}
    }      
}     

据我所知,您定义的 TargetGroup 没有 TargetType,这意味着默认情况下它设置为 instance。 ECS 服务需要 TargetType 设置为 ip,这是 awsvpc 唯一支持的选项。在您的 CloudFormation 中只需添加:

"TargetType": "ip",

这应该可以解决您的问题。如果仍然有问题,请从 CloudFormation 控制台提供错误信息。