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

标签 amazon-web-services yaml aws-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:
      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 create-stack --stack-name app-cluster --template-body file://infra/app-cluster.yml

错误是:调用 CreateStack 操作时发生错误 (ValidationError):无效的模板属性或属性 [???AWSTemplateFormatVersion]

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

感觉我必须错过一些简单的东西,但我只是没有看到它。谢谢

最佳答案

三个“???”表示您有 BOM在你的文件中。

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

关于amazon-web-services - AWS Cloudformation 创建堆栈模板错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60921810/

相关文章:

bash - 如何仅使用 bash(无编辑器)创建 Kubernetes YAML 部署对象?

amazon-web-services - 有没有办法让 CloudFormer(测试版)将用户数据保留在启动配置中

python - cfnbootstrap 文件夹在哪里?

aws-api-gateway - 尝试通过 Cloudformation 创建 AWS API 网关时出现错误

amazon-web-services - 调用 aws cli 的用户数据脚本

yaml - 无服务器组件 yaml 中引用云形成堆栈

linux - 亚马逊网络服务 (AWS) - 亚马逊 Linux : How to install libel-dev and g++?

javascript - Gatsby - 在解析/显示 YAML 文件内容时是否可以保留换行符?

amazon-web-services - 如何使用 cloudformation 从 S3 ARN 获取 S3 存储桶名称

python - 即使关闭本地机器,如何在 AWS EC2 上运行进程?