[英]How to use !Sub or !Join in "AWS::CloudFormation::Init", file key
I'm currently creating a yaml template and I'm trying to modularize templates so that they can be re-used across different projects.我目前正在创建一个 yaml 模板,我正在尝试模块化模板,以便它们可以在不同的项目中重复使用。 The issue I'm having is that I keep getting syntax errors if I try to use.Join or !Sub in file name.
我遇到的问题是,如果我尝试在文件名中使用 .Join 或 !Sub,我会不断收到语法错误。
files:
/tmp/myfile2.txt:
content: "/tmp/myfile1.txt"
mode: "120644"
I want to create a project specific directory instead of /tmp/, for example:我想创建一个项目特定目录而不是 /tmp/,例如:
files:
/PROJECT_NAME/myfile2.txt:
content: "/tmp/myfile1.txt"
mode: "120644"
PROJECT_NAME being a CloudFormation parameter. PROJECT_NAME 是 CloudFormation 参数。
Is it possible to achieve something like this:是否有可能实现这样的目标:
files:
!Sub "/${PROJECT_NAME }/myfile2.txt":
content: |
some shell commands
some shell commands
some shell commands
mode: "120644"
I tried multiple ways of achieveing this, using,Join: Fn:,Sub.我尝试了多种方法来实现这一点,使用 Join: Fn:,Sub。 !Sub.
!子。
Just wondering if anyone had done anything like this before?只是想知道以前是否有人做过这样的事情?
Thank you!谢谢!
Just wondering if anyone had done anything like this before?
只是想知道以前是否有人做过这样的事情?
Many people tried and filed.许多人尝试并提交。 The reason is that you can't use non-strings as maps in CloudFormation.
原因是您不能在 CloudFormation 中使用非字符串作为映射。 From CFN format specification :
来自CFN 格式规范:
A map is a collection of key-value pairs, where the keys are always strings .
map是键值对的集合,其中键始终是字符串。
Therefore, a proposed solution is to use UserData
to define the dynamically generate file, instead of using CFN metadata.因此,建议的解决方案是使用
UserData
来定义动态生成的文件,而不是使用 CFN 元数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.