【问题标题】:AWS Cloudformation - Importing Jinja defined variables in YAML filesAWS Cloudformation - 在 YAML 文件中导入 Jinja 定义的变量
【发布时间】:2018-12-29 02:22:32
【问题描述】:

我在 Jinja 文件中生成了一些 Cloudwatch 警报。我想将 YML 文件中的这些警报之一用于 cloudformation。简单地输入DependsOn 不起作用,因为进程失败并显示错误提示

"StatusReason": "Template format error: Unresolved resource dependencies [ABC.Alarm] in the Resources block of the template",

在 Cloudformation 部署的 YML 文件中导入 Jinja 变量的方法是什么?

编辑:

我们的配置包含 YML 和 Jinja 文件,我不打算替换完整的模板。但只是使用 Jinja 文件中定义的参数。

【问题讨论】:

    标签: amazon-web-services jinja2 amazon-cloudformation


    【解决方案1】:

    yaml模板被Jinja替换的方式有多种。

    【讨论】:

    • 我不想替换完整的模板。但只是使用 Jinja 文件中定义的参数。
    【解决方案2】:

    您可能还不想生成 CloudFormation 模板。更好地利用CloudFormation parameters

    您可以使用ansible 来预处理甚至“执行”模板。

    Ansible 具有 cloudformation 模块,您可以将要创建/更新的堆栈的名称传递给它,并且可以传递模板参数。

    在 Ansible 剧本中experiments.yml:

    - hosts: localhost
      connection: local
      gather_facts: False
    
      tasks:
        - cloudformation:
            stack_name: experiments
            template: experiments-stack.yml
            template_parameters:
                MyParameter: MyParameterValue
    

    CloudFormation 堆栈模板experiments-stack.yml:

    ...
    
    Parameters:
        MyParameter:
            Type: String
    
    Resources:
        Something:
            Type: ...
            Properties:
            PropertyName: !Ref MyParameter
    

    使用ansible-playbook ./experiments.yml 运行剧本

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-07
      • 2018-09-16
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 2022-10-15
      • 2021-01-05
      相关资源
      最近更新 更多