无法通过cloudformation yaml创建AWS :: ECS :: Service,模型验证失败 [英] Could not create AWS::ECS::Service via cloudformation yaml, got Model validation failed
问题描述
在通过cloudformation创建 AWS :: ECS :: Service
的过程中,出现错误:模型验证失败
During creation of AWS::ECS::Service
via cloudformation i got the error: Model validation failed
该错误与 #HealthCheckGracePeriodSeconds
和其他一些属性有关.错误详细信息是:期望的类型:数字,找到的:字符串
.
The error is related to #HealthCheckGracePeriodSeconds
and some other properties. Error detail is: expected type: Number, found: String
.
在yaml中,它已经是一个数字.我不清楚发生了什么问题.已经尝试将其声明为字符串或类型为Number的参数.
In yaml it is already a number. It's not clear to me whats going wrong. Already tried to desclare it as string or as parameter with type Number.
我需要一些提示,因为此时我陷入了困境.
I need some hint because i am stuck in the muck at this point.
错误是:
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中的定义是:
Definition in template.yaml is:
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]
推荐答案
导致此错误是因为 SecurityGroups
和 Subnets
格式错误.
The error was caused because SecurityGroups
and Subnets
resulted in a wrong format.
要提取子网
和 securitygroups
,请使用 FindInMap
函数.此结果必须是列表.这可以使用 Split
函数来实现.
To extract subnets
and securitygroups
the FindInMap
function was used. It is necessary that this result is a list. This can be achieved using the Split
function.
不幸的是,格式错误会导致完全错误的错误消息.
The wrong format unfortunately leads to a completely misleading error message.
声明这样的映射:
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
结合使用!Split
和!FindInMap
以获得列表:
Use !Split
combined with !FindInMap
to get a list:
SecurityGroups: !Split [",", !FindInMap [ Env2SecurityGroups, !Ref AWS::AccountId, securitygroup] ]
Subnets: !Split [",", !FindInMap [ Env2PublicSubnets, !Ref AWS::AccountId, subnets] ]
这篇关于无法通过cloudformation yaml创建AWS :: ECS :: Service,模型验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!