Amazon cloudformation 无法通过cloudformation yaml创建AWS::ECS::Service,获取模型验证失败

Amazon cloudformation 无法通过cloudformation yaml创建AWS::ECS::Service,获取模型验证失败,amazon-cloudformation,amazon-ecs,Amazon Cloudformation,Amazon Ecs,在通过cloudformation创建AWS::ECS::Service的过程中,我遇到了错误:模型验证失败 该错误与#HealthCheckGracePeriodSeconds和其他一些属性有关。错误详细信息为:预期类型:编号,找到:字符串 在yaml中,它已经是一个数字。我不清楚出了什么问题。已尝试将其定义为字符串或具有类型编号的参数 我需要一些提示,因为我现在陷入了困境 错误是: Model validation failed ( #/HealthCheckGracePe

在通过cloudformation创建
AWS::ECS::Service
的过程中,我遇到了错误:
模型验证失败

该错误与
#HealthCheckGracePeriodSeconds
和其他一些属性有关。错误详细信息为:
预期类型:编号,找到:字符串

在yaml中,它已经是一个数字。我不清楚出了什么问题。已尝试将其定义为字符串或具有类型编号的参数

我需要一些提示,因为我现在陷入了困境

错误是:

Model validation failed 
    (
    #/HealthCheckGracePeriodSeconds: expected type: Number, found: String 
    #/DesiredCount: expected type: Number, found: String 
    #/DeploymentConfiguration/MaximumPercent: expected type: Number, found: String 
    #/DeploymentConfiguration/MinimumHealthyPercent: expected type: Number, found: String
    )
template.yaml中的定义是:

ServiceDefinition:
  Type: AWS::ECS::Service
  Properties:
    ServiceName: !Ref ServiceName
    Cluster: !Ref ClusterName
    TaskDefinition: !Ref TaskDefinition
    DeploymentConfiguration:
      MinimumHealthyPercent: 100
      MaximumPercent: 200
    DesiredCount: 1
    HealthCheckGracePeriodSeconds: 60
    LaunchType: FARGATE
    NetworkConfiguration:
      AwsVpcConfiguration:
        AssignPublicIP: ENABLED
        SecurityGroups: !FindInMap [Env2SecurityGroups, !Ref AWS::AccountId, securitygroup]
        Subnets: !FindInMap [Env2PublicSubnets, !Ref AWS::AccountId, subnets]

导致此错误的原因是
安全组
子网
导致格式错误

为了提取
子网
安全组
,使用了
FindInMap
功能。这个结果必须是一个列表。这可以通过使用
Split
功能来实现

不幸的是,错误的格式会导致完全误导的错误消息

如下所示声明映射:

Mappings
  Env2SecurityGroups:
    '111111111111':
      securitygroup: 'sg-1111111111111111'
    '222222222222':
      securitygroup: 'sg-2222222222222222'
    '333333333333':
      securitygroup: 'sg-3333333333333333'

  Env2PublicSubnets:
    '111111111111':
      subnets: subnet-1111111111111111,subnet-22222222222222222,subnet-33333333333333333
    '222222222222':
      subnets: subnet-1111111111111111,subnet-22222222222222222,subnet-33333333333333333
    '333333333333':
      subnets: subnet-1111111111111111,subnet-22222222222222222,subnet-33333333333333333
使用
!拆分
组合使用!查找地图
以获取列表:

SecurityGroups: !Split [",", !FindInMap [ Env2SecurityGroups, !Ref AWS::AccountId, securitygroup] ]
Subnets: !Split [",", !FindInMap [ Env2PublicSubnets, !Ref AWS::AccountId, subnets] ]

这个看起来不错。您确定这是给出错误的资源吗?类似于我很好奇您是如何解决“expected type:Number”错误的,因为我在设置任务定义时遇到了相同的错误。不清楚这个答案与问题中的错误有什么关系。实际上我想我现在明白了。这个错误似乎有误导性。数字转换实际上不是故障的原因。故障在其他地方,CF报告错误。只是另一个云层形成的问题。错误在任何方面都不一定与问题有关。在我的情况下,我需要在错误列表中进一步查找,以找到一个更有意义的错误,并整理出误导性错误。我认为这可能与错误完全相关,但方式不同。模板某些部分的无效值可能会导致其他副作用,这些副作用只有在运行时才能知道。例如,当Import语句返回特殊字符(如不均匀引号)时,它可能会损坏整个文件,导致运行时出现意外错误