我有一个要在实例上运行的bash脚本,但我只想在值为true的情况下运行脚本的第二部分。另外,我不希望if语句出现在脚本中。
Parameters:
#TestParameter = TRUE
Resource:
UserData:
Fn::Sub: |
echo "This is a test example"
#If TestParameter is true:
echo "Only is parameter is true"发布于 2019-02-06 21:45:40
在我看来,更好的方法是在脚本中构造Sub参数:
UserData:
Fn::Sub: |
echo "This is a test example"
if ${TestParameter}; then
echo "Only is parameter is true"
fi但是,由于您不希望在脚本中包含if,因此必须在Cloudformation模板中构造脚本的主体。在CFN中构建字符串总是很麻烦的。尝试如下所示:
UserData:
Fn::Join: ["\n", ["echo 'This is a test example'",
['Fn::If': [!Equals [!Ref TestParameter, "true"], "echo 'Parameter is true'", ""]]]]https://stackoverflow.com/questions/54541240
复制相似问题