Amazon web services AWS Cloudformation创建堆栈模板错误

Amazon web services AWS Cloudformation创建堆栈模板错误,amazon-web-services,yaml,amazon-cloudformation,amazon-ecs,Amazon Web Services,Yaml,Amazon Cloudformation,Amazon Ecs,因此,我试图在CF中为API提供一些资源。我有下面的yml文件,但我一直得到一个模板错误,无法看到问题 AWSTemplateFormatVersion: "2010-09-09" Description: 'container cluster on ECS, loadbalancer, security groups and cloudwatch' Resources: ECSCluster: Type: AWS::ECS::Cluster Properties:

因此,我试图在CF中为API提供一些资源。我有下面的yml文件,但我一直得到一个模板错误,无法看到问题

AWSTemplateFormatVersion: "2010-09-09"
Description: 'container cluster on ECS, loadbalancer, security groups and cloudwatch'

Resources:

  ECSCluster:
    Type: AWS::ECS::Cluster
    Properties:
      ClusterName: 'hello-cluster'

  LoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Name: ecs-services
      Subnets:
        #these imports will pull from export name of the vpc stack that we made
        - 'subnet-abcdefg'
        - 'subnet-abcdefo'
        - 'subnet-abcdefp'
      SecurityGroups:
        #references the LoadBalancerSecurityGroup below
        - !Ref LoadBalancerSecurityGroup

  #port 80 for POC, then add 443
  LoadBalancerListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      #references LoadBalancer above
      LoadBalancerArn: !Ref LoadBalancer
      Protocol: HTTP
      Port: 80
      DefaultActions:
        - Type: forward
          #references target group below
          TargetGroupArn: !Ref DefaultTargetGroup

  #this is very open, we won't want this
  LoadBalancerSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Security group for loadbalancer to services on ECS
      VpcId: 'vpc-abcdefg'
      SecurityGroupIngress:
        - CidrIp: 0.0.0.0/0
          IpProtocol: -1

  DefaultTargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Name: default
      #imports vpc export name from previous stack
      VpcId: 'vpc-abcdefg'
      Protocol: 'HTTP'
      Port: '80'  

  #extranious for now
  CloudWatchLogsGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: 'apis'
      RetentionInDays: 1

  ## security group for containers simliar to load balancer getting connections from the internet,
  ## this will allow connections from the load balancer
  ContainerSecurityGroup:
    Type: AWS::EC2::SecurityGroup      
    Properties:
     VpcId: 'vpc-abcdefg'
     GroupDescription: for ecs containers
     SecurityGroupIngress:
       - SourceSecurityGroupId: !Ref 'LoadBalancerSecurityGroup'
         IpProtocol: -1


Outputs:

  Cluster:
    Value: !Ref ECSCluster
    Export:
      Name: 'ECSCluster'

  Listener:
    Description: listener port 80
    Value: !Ref LoadBalancerListener
    Export:
      Name: 'Listener'

  ContainerSecurityGroup:
    Description: container security group
    Value: !Ref ContainerSecurityGroup
    Export:
      Name: 'ContainerSecurityGroup'

  LoadBalancerDNS:
    Description: Domain name for the loadbalancer
    Value: !GetAtt LoadBalancer.DNSName
    Export:
      Name: 'DomainName'
当我运行它来创建堆栈时,它会给我一个错误

aws cloudformation创建堆栈--堆栈名称应用程序集群--模板正文file://infra/app-cluster.yml 错误是:
调用CreateStack操作时发生错误(ValidationError):无效的模板属性或属性[???AWSTemplateFormatVersion]

当我删除前两行并将第一行设置为“Resources”时,我收到此错误
调用CreateStack操作时发生错误(ValidationError):模板格式错误:必须至少定义一个Resources成员。

我觉得我必须错过一些简单的东西,但我就是看不到。谢谢

三个“?”表示您的文件中有

请将模板文件保存为UTF-8(无BOM),它应该可以解决此问题。这将取决于您的。三个“?”表示您的文件中有


请将模板文件保存为UTF-8(无BOM),它应该可以解决此问题。这将取决于您的。

我已尝试使用UI创建您的模板,它正在工作。。AWS CLI命令似乎有问题。我猜YAML不知怎么被损坏了。也使用cli进行了检查,它工作了,您的文件100%损坏了。我尝试使用UI创建您的模板,它工作了。。AWS CLI命令似乎有问题。我猜YAML不知怎么被破坏了。也使用cli进行了检查,并且正常工作,您的文件100%被破坏了。谢谢。我疯狂地想弄清楚剧本本身到底出了什么问题!谢谢我疯狂地想弄清楚剧本本身到底出了什么问题!