[英]Cloudformation conditional statement
I am trying to create a stack for ECS service with conditional statement for logging on ECS TaskDefination.我正在尝试使用用于登录 ECS TaskDefination 的条件语句为 ECS 服务创建堆栈。 I am trying to send the logs to different sources based on Environment but it is failing with below during stack update.我正在尝试根据环境将日志发送到不同的来源,但在堆栈更新期间失败。
Error Resource handler returned message: "Model validation failed (#/ContainerDefinitions/0/Memory: expected type: Number, found: String #/ContainerDefinitions/0/Cpu: expected type: Number, found: String #/ContainerDefinitions/0/LogConfiguration: expected type: JSONObject, found: JSONArray #/ContainerDefinitions/0/PortMappings/0/ContainerPort: expected type: Number, found: String)"错误资源处理程序返回消息:“模型验证失败(#/ContainerDefinitions/0/Memory:预期类型:数字,找到:字符串#/ContainerDefinitions/0/Cpu:预期类型:数字,找到:字符串#/ContainerDefinitions/0/LogConfiguration :预期类型:JSONObject,发现:JSONArray #/ContainerDefinitions/0/PortMappings/0/ContainerPort:预期类型:数字,发现:字符串)”
Conditions:
HasDefaultLog:
!Or [ !Equals [ !Ref EnvType, 'Prod' ], !Equals [ !Ref EnvType, 'Dev' ], !Equals [ !Ref EnvType, 'Sit' ] ]
ContainerDefinitions:
- Name: !Ref 'ServiceName'
Cpu: !Ref 'ContainerCpu'
Memory: !Ref 'ContainerMemory'
Image: !Ref 'ImageUrl'
PortMappings:
- ContainerPort: !Ref 'ContainerPort'
LogConfiguration:
-
Fn::If:
- HasDefaultLog
-
LogDriver: !Ref LogDriver
Options:
syslog-address: !Ref LogDestination
tag: !Ref ServiceName
-
LogDriver: awsfirelens
Options:
Name: newlogdriver
The same works with below and able to see the logs in destination同样适用于下面并且能够看到目标中的日志
LogConfiguration:
LogDriver: !Ref LogDriver
Options:
syslog-address: !Ref LogDestination
tag: !Ref ServiceName
LogConfiguration
is object, not a list of objects. LogConfiguration
是对象,而不是对象列表。 Sp you don't need -
at the beginning:您不需要的 Sp -
开始时:
LogConfiguration:
Fn::If:
- HasDefaultLog
-
LogDriver: !Ref LogDriver
Options:
syslog-address: !Ref LogDestination
tag: !Ref ServiceName
-
LogDriver: awsfirelens
Options:
Name: newlogdriver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.