[英]AWS cloud form task definition conditional command
Let say I have an app that has the ability to run in a dry run mode, set by a flag on the command line; 假设我有一个能够在命令行中通过标志设置的空运行模式下运行的应用; myapp --dryrun
, and the CloudForm for its task definition is: myapp --dryrun
,其任务定义的myapp --dryrun
为:
MyTaskDefinition
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Name: myApp
Image: user/myapp:latest
Command:
- ./myapp
- --dryrun
Environment:
- Name: SOME_ENV_VAR
Value: !Ref SomeEnvVar
I am trying to create a single CloudForm template for a Task Definition that can be used in a development and production environment, where the dry run flag is set only for the development environment. 我正在尝试为任务定义创建单个CloudForm模板,该模板可以在开发和生产环境中使用,其中仅针对开发环境设置了空运行标志。
Is there some way to set conditional command, or am I going to resort to a hacky string that I pass in like: 有什么方法可以设置条件命令,还是我要诉诸于我传入的hacky字符串:
Command:
- ./myapp
- !Ref DryRun
The neatest solution was to use an If
function, which sets the flag when true, and uses AWS::NoValue
if false. 最简单的解决方案是使用If
函数,该函数将标志设置为true, If
设置为false,则使用AWS::NoValue
。
AWS::NoValue
will remove the property completely, meaning the command for true is ["./myapp", "--dryrun"]
and the command when false is ["./myapp"]
. AWS::NoValue
将完全删除该属性,这意味着true的命令为["./myapp", "--dryrun"]
,false时的命令为["./myapp"]
。
Unfortunately, there is no Bool
type for CloudForm parameters, and so you have to pass this in as a String
, and then use a Condition
to convert from the String
to a Bool
. 不幸的是,CloudForm参数没有Bool
类型,因此您必须将其作为String
传入,然后使用Condition
从String
转换为Bool
。
MyTaskDefinition
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Name: myApp
Image: user/myapp:latest
Command:
- ./myapp
- Fn::If:
- UseDryRun
- --dryrun
- Ref: AWS::NoValue
Parameters:
DryRun:
Type: String
AllowedValues: # No bool parameter in CFN
- true
- false
Conditions:
UseDryRun: !Equals [ !Ref DryRun, true ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.