简体   繁体   English

使用方法:Sub 或:Join in "AWS::CloudFormation,:Init", file key

[英]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.

相关问题 如何使用 CloudFormation 更新 AWS Glue 作业 - How to use CloudFormation to update AWS Glue Jobs 如何在 cloudformation 的参考参数中使用 AWS principal - How to use AWS principal in reference parameter in cloudformation 如何使用 CloudFormation Init 创建没有任何内容的文件? - How to create a file without any content using CloudFormation Init? AWS CloudFormation中如何使用email动态列表订阅SNS主题? - How to use email dynamic list to SNS Topic Subscription in AWS CloudFormation? Cloudformation 如何在 Sub 内部的 ImportValue 内部进行 Sub? - Cloudformation how to Sub inside of a ImportValue inside of a Sub? AWS Cloudformation:无法在 cfn-init 或 UserData 中访问网络共享驱动器 - AWS Cloudformation: Network Share Drive is inaccessible in cfn-init or UserData 如何在开发环境中使用没有服务 key.json 文件的谷歌服务,如 bucket 或 pub sub? - How to use the google services like bucket or pub sub without service key.json file in development environment? 如何在 AWS CloudFormation 模板中使用参考号 function? - How is the !Ref function used in an AWS CloudFormation template? 如何为特定 AWS 账户运行 CloudFormation - How to run CloudFormation for a specific AWS Account 如何在 AWS cloudformation 中将两个条件“和”在一起 - how to "and" two conditions together in AWS cloudformation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM